[英]How to initialise mongoose schema in mongoDb?
我想在node.js應用程序啟動/與數據庫的貓鼬連接上為所有架構/模型文件創建數據庫和集合。 (不播種數據庫,而是在db上初始化/設置結構模式)
我的模特:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
// define the schema
var modelSchema = new Schema({
appId: {
type: String,
indexed: true
}
});
// export the Model
module.exports = mongoose.model('Model', modelSchema)
我正在使用這種方法連接到數據庫:
mongoose.connect(mongodbUri, mongooseOptions);
目前,僅當我向數據庫中插入內容時,貓鼬才會在db中創建模式。
如果您修復indexed
是index
架構中的,這最終將建立你的收藏,這樣當你創建模型的指數也可以被創建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.