[英]month wise collection in mongodb using mongoose?
我正在嘗試使用mongodb SEP_2019
進行簡單演示,但是我的問題是我想創建month wise collection
示例SEP_2019
, OCT_2019
, DEC_2019
每個收集模式都是相同的
var personSchema = new Schema({
name: String
});
我的架構中只有一個attribute/field name
。
所以我的收藏有這種類型的數據
`SEP_2019`
[{
name:'test'
}]
所以我想在當月的基礎上動態創建集合,將我的數據插入該集合中,同時從集合中retrieve
該數據。還要在集合中查詢該數據?
我將使用mongoos
還是mongo client
?
對於貓鼬,集合名稱是在您通過架構創建模型時定義的。
您將執行以下操作:
const mongoose = require('mongoose');
var personSchema = new Schema({
name: String
});
const Sep2019 = mongoose.model('SEP_2019', personSchema)
let newPerson = Sep2019.create({name: 'test'});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.