Mongodb findAndModify节点js [英] Mongodb findAndModify node js

查看:182
本文介绍了Mongodb findAndModify节点js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在节点js中给出了异常,说:需要删除或更新

Following code gives me exception in node js saying: "need 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) {

    }
);

.findAndRemove()

这篇关于Mongodb findAndModify节点js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆