.updateOne on MongoDB not working in Node.js

后端 未结 8 1033
迷失自我
迷失自我 2021-01-03 20:07

I have the following code:

connection((db) => {
            db.collection(\'orders\')
                .updateOne(
                    { \"_id\": req.body         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 20:51

    Tough @Spraw's answer is right for some cases, but sometimes it doesn't work. I think the convenient answer is updateOne({_id: new ObjectID(req.body._id)}, {$set: {"name": req.body.name}}, callback).

    the _id in mongodb is a BSON object and should be instantiated.

提交回复
热议问题