0
var UserData = function(){
var self = this;
this.schema = Schema({
userID: String,
firstName: String,
lastName: String,
...
//many other fields.
...
isActive: {type: "Boolean", default: true}
}, { collection: 'UserData' });
this.model = db.model('UserData', self.schema);
this.upsert = function(object){
//some logic
self.model.update({userID: object.userID}, object, {upsert: true}, function(err){...});
};
}
此代碼工作正常,除isActive將在覆蓋期間被覆蓋。如何從Mongoose中的「upsert-ed」中排除字段?
我想要實現這樣的邏輯:
- 默認isActive成爲新的記錄真實。
- 什麼時候做upsert,請保持isactive不變。
如何實現這一目標?提前致謝!