假设我有一个架构定义
var Users = mongoose.model('Users', new mongoose.Schema({
username: String,
salt: String,
hash: String,
facebook: {
id: String
}
}));
但我想稍后
user = new Users({
username: 'myusername',
facebook: {
id: '3141592653',
displayName: 'mydisplayname' // <- wasn't in the schema ^
}
});
然后displayName
根本没有存储。猫鼬不允许这样吗?因为我会想象,因为MongoDB是“无模式”的,所以应该有办法做到这一点吗?
答案 0 :(得分:1)
您可以禁用架构上的strict
选项,以允许保存架构中没有的字段:
var Users = mongoose.model('Users', new mongoose.Schema({
username: String,
salt: String,
hash: String,
facebook: {
id: String
}
}, { strict: false }));