我想更新一个数组并返回文档。我的 findAndModify 语法是否正确?
this.becomeFollower = function(title, username, callback){
"use strict"
posts.findAndModify({
query: {"title":title, "roster":"yes"},
update: { "$addToSet": { "followers":username } },
new: true,
upsert: true
},
function(err, doc){
console.log('find and modified ' +doc);
});
}
我使用这个没有问题:
posts.update({"title":title, "roster":"yes"}, { "$addToSet": { "followers":username } }, function(err, roster){
"use strict"
if(err) return callback(err, null);
callback(err, roster);
});