在以前版本的Mongoose(对于node.js)中,有一个选项可以在不定义模式的情况下使用它
var collection = mongoose.noSchema(db, "User");
但在当前版本中,"noSchema"功能已被删除.我的模式可能会经常更改,并且确实不适合已定义的模式,所以在mongoose中是否有一种新的方法来使用无模式模型?
在以前版本的Mongoose(对于node.js)中,有一个选项可以在不定义模式的情况下使用它
var collection = mongoose.noSchema(db, "User");
但在当前版本中,"noSchema"功能已被删除.我的模式可能会经常更改,并且确实不适合已定义的模式,所以在mongoose中是否有一种新的方法来使用无模式模型?
我想这就是你想要的Mongoose Strict
option: strict
strict选项(默认情况下启用)确保添加到模型实例中的、未在模式中指定的值不会保存到数据库中.
Note: Do not set to false unless you have good reason.
var thingSchema = new Schema({..}, { strict: false });
var Thing = mongoose.model('Thing', thingSchema);
var thing = new Thing({ iAmNotInTheSchema: true });
thing.save() // iAmNotInTheSchema is now saved to the db!!