UpdateMany in MongoDB running twice with $inc

后端 未结 2 963
耶瑟儿~
耶瑟儿~ 2021-01-15 20:44

Thanks to the help received in my previous question (UpdateMany mongodb documents with value from document), I have learned about incrementing using updateMany. I wrote the

2条回答
  •  轮回少年
    2021-01-15 21:04

    Per comments on the original question, I was able to solve this by removing the .catch and the await.

    ageAllCameraPriorities = async (req, res) => {
        Camera.updateMany(  { enabled: true },
            { $inc: { processingPriority: req.params.amount } },
            {},
            (err, dbResp) => {
            if (err) {
                return res
                    .status(400)
                    .json({ success: false, error: "Status 400, unable to age camera priorities" + err })
            }
            if (!dbResp.n) {
                return res
                    .status(404)
                    .json({ success: false, error:'No enabled cameras found to age' })
            }
                return res
                    .status(200)
                    .json({ success: true, data: dbResp })
        })
    }
    

提交回复
热议问题