Error: the update operation document must contain atomic operators, when running updateOne

后端 未结 4 574
北恋
北恋 2020-12-05 03:41

In my collection, there is only one document.

> db.c20160712.find()
{ \"_id\" : ObjectId(\"57ab909791c3b3a393e9e277\"), \"Dimension_id\" : 2, \"Attribute\         


        
4条回答
  •  -上瘾入骨i
    2020-12-05 04:22

    You should use this code because I was also facing the same problem and then I used this code:

    updateOne(
        { _id: new ObjectID(req.params.id) },
        { $set: { title: req.body.bookName, author: req.body.authorName } },
        { upsert: true }
    )
    

    and you should also define ObjectID otherwise the problem will occur again.

    const ObjectID = require('mongodb').ObjectID;
    

提交回复
热议问题