Mongodb findAndModify 节点js [英] Mongodb findAndModify node js
本文介绍了Mongodb findAndModify 节点js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码在 node js 中给了我一个异常说:需要删除或更新"
Following code gives me an exception in node js saying: "need to remove or update"
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);
}
});
无法找出问题,因为我已指定更新操作.
Not able to figure out the issue as I have specified the update operation.
推荐答案
节点驱动程序中的语法与节点驱动程序中的语法不同shell,这是您正在使用的语法.
The syntax is different in the node driver than for the shell, which is the syntax you are using.
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) {
}
);
这篇关于Mongodb findAndModify 节点js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文