1

I have this data in mongodb and i want update it with one query:

{ 
"_id" : ObjectId("zzzzz6e57fss8ssb9cssbsss"), 
"user" : "zzzz", 
"data" : [
    {
        "_id" : ObjectId("zzzzz6e57ffe8b2b9c77b6b9"),  
        "me" : "LLL"
    }, 
    {
        "_id" : ObjectId("5b8ab719406d7235240f4338"), 
        "me" : "III"
    }
]
"__v" : NumberInt(0)
}

and i want to change 'me' : 'III' by findOneAndUpdate This code didn't work.

var ObjectID = require('mongodb').ObjectID;
var o_id = new ObjectID("5b8ab719406d7235240f4338");
array.findOneAndUpdate
(
    { 'data._id' : o_id    },
    {  $set:{'me' : "Stackoverflow"    }   }, 
    function (error, success) 
    {
        if (error) console.log(error);
        if(success == null )
            console.log("nullllllllllllllllllllllll");
        console.log(success);
    }
);

1 Answer 1

1
var ObjectID = require('mongodb').ObjectID;
var o_id = new ObjectID("5b8ab719406d7235240f4338");
array.findOneAndUpdate
(
    { 'data._id' : o_id    },
    {  $set:{'data.$.fr' : "Stackoverflow"    }   }, 
    function (error, success) 
    {
        if (error) console.log(error);
        if(success == null )
            console.log("nullllllllllllllllllllllll");
        console.log(success);
    }
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.