我有一个带有一些默认行为的 mongo 文档
var thingSchema = new mongoose.Schema(
things:
first: {
type: Boolean,
default: false
},
second: {
type: Boolean,
default: false
}
);
var myThings = mongoose.model('Things', thingsSchema);
如果我先更新
myThings.update({things: {first: true}});
和输出Things
Things.find(function(err, things){
console.log(things) // {things: {first: true}, {second: false}}
});
然后我更新第二个值
myThings.update({things: {second: true}});
当我再次输出时,我得到{things: {first: false}, {second: true}}
了,而不是所需的{things: {first: true}, {second: true}}
.
无需每次都传递first
和second
值update
,如何防止模型恢复到默认行为?