Reputation: 257
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);
}
);
Upvotes: 1
Views: 749
Reputation: 257
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);
}
);
Upvotes: 1