以下代码在 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);
}
});
无法找出问题,因为我已指定更新操作。
语法节点驱动程序不同 http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#findandmodify与 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() http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#findandremove
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)