以下代码在 Node js 中给了我一个异常:“需要删除或更新”
var args = {
query: { _id: _id },
update: { $set: data },
new: true,
remove: false
};
db.collection(COLLECTION.INVENTORY_LOCATION)
.findAndModify(args, function (err, results) {
if (err) {
return callback(err);
} else {
console.log(results);
callback(null, results);
}
});
由于我指定了更新操作,所以无法解决问题。
最佳答案
语法is different in the node driver而不是 shell,这是您正在使用的语法。
db.collection("collection_name").findAndModify(
{ _id: _id }, // query
[], // represents a sort order if multiple matches
{ $set: data }, // update statement
{ new: true }, // options - new to return the modified document
function(err,doc) {
}
);
.findAndRemove()
有一个单独的函数
关于javascript - Mongodb findAndModify Node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24648610/