Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法使用FindByidUpdate和$eq进行更新_Node.js - Fatal编程技术网

Node.js 无法使用FindByidUpdate和$eq进行更新

Node.js 无法使用FindByidUpdate和$eq进行更新,node.js,Node.js,我可以使用以下代码更新数据: router.post('/source/savesource/:id', JWTAuthenticatToken, async (req, res) => { const { sourcename, sourcedescription } = sanitize(req.body.sourceData) try { if (req.cookies.sessionCookie === req.body.csrf) {

我可以使用以下代码更新数据:

router.post('/source/savesource/:id', JWTAuthenticatToken, async (req, res) => {
    const { sourcename, sourcedescription } = sanitize(req.body.sourceData)
    try {
        if (req.cookies.sessionCookie === req.body.csrf) {
            const Source = await Source.findByIdAndUpdate({_id: req.params.id},
                {
                    $set: {
                        sourcename: sourcename,
                        sourcedescription: sourcedescription
                    }
                }, { new: true })
            return res.json({ statusCode: "200" })
        }

    } catch (error) {
        res.json({ message: error })
    }
})
但当我尝试添加$eq时,它并没有更新,也没有给出任何错误

router.post('/source/savesource/:id', JWTAuthenticatToken, async (req, res) => {
    const { sourcename, sourcedescription } = sanitize(req.body.sourceData)
    try {
        if (req.cookies.sessionCookie === req.body.csrf) {
            const Source = await Source.findByIdAndUpdate({ _id: { "$eq": req.params.id }},
                {
                    $set: {
                        sourcename: sourcename,
                        sourcedescription: sourcedescription
                    }
                }, { new: true })
            return res.json({ statusCode: "200" })
        }

    } catch (error) {
        res.json({ message: error })
    }
})
我的问题是允许我使用$eq吗?或者我的语法有问题


非常感谢您的帮助。

我不确定
findbyiandupdate
是否能与比较运算符一起使用。如果有必要,请尝试
findOneAndUpdate
。顺便说一句,你不需要大约$eq.@Christian的引用分数。谢谢