model层
var schema =new Schema({
orname:String,
userIds:[{userId:String}],
create_at:{type: Date,default: Date.now}
});
controller层
logs.get(id, function(err,log){
if(log){
log.userIds.push('eu128765edddidodiddyydhdjkuyttdj');
log.save();
}
})
问题原因:mongodb很早前的版本就合并了$push和$pushAll,然后mongodb 3.6取消了$pushAll
解决方案:
(1)mongodb降级到3.4或mongoose升级到5.0 rc2,亲测降级3.4是OK的
(2)在Schema中传入第二个参数{usePushEach: true}。
new mongoose.Schema({
orname:String,
userIds:[{userId:String}],
create_at:{type: Date,default: Date.now}
}, {
usePushEach: true
});
网友评论