【发布时间】:2015-02-14 00:02:37
【问题描述】:
我想为 node.js 应用程序启动/mongoose 连接到 db 上的所有模式/模型文件创建数据库和集合。 (不是为数据库播种,而是在 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);
目前 mongoose 仅在我向数据库中插入内容时才会在 db 中创建模式。
【问题讨论】:
-
是的,你是对的,这是一个愚蠢的错误。我虽然那个索引选项确实存在。