.updateOne on MongoDB not working in Node.js

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

I have the following code:

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


        
8条回答
  •  春和景丽
    2021-01-03 20:43

    Maybe you should use "$set" in your update query like this :

    {$set: {"name": req.body.name}}, // Update
    

    More information in documentation

    EDIT

    If it doesn't work, this is probably because there is no match with your filter.

    Maybe you should try to match with an ObjectId like this :

    var ObjectID = require('mongodb').ObjectID;
    
    // In your request
    { "_id": ObjectID(req.body._id)}, // Filter
    

    Hope it helps.

提交回复
热议问题