如何防止值在mongoose更新期间恢复为默认值

时间:2013-07-09 11:11:34

标签: javascript node.js mongodb mongoose

我有一个带有一些默认行为的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}}

每次都不必将firstsecond值都传递给update,我怎样才能让我的模型不会恢复到默认行为?

0 个答案:

没有答案