0

In this data in mongodb i want to update user by _id.

{
    "_id" : ObjectId("aaaab51b080ddbaaaa2db6da"), 
    "user" : "1111", 
}
{ 
    "_id" : ObjectId("aaaab564ef9aaaa640adf2a9"), 
    "user" : "2222"
}

But i want this output:

{
    "_id" : ObjectId("aaaab51b080ddbaaaa2db6da"), 
    "user" : "1111", 
}
{ 
    "_id" : ObjectId("aaaab564ef9aaaa640adf2a9"), 
    "user" : "2222Helooword"   //user + "Helooword"
}

I mean user +"Helooword". I want append "Helooword" to user. I use this code but it dose not work. I want to use ONE query .(findOneAndUpdate)

var ObjectID = require('mongodb').ObjectID;
var o_id = new ObjectID("aaaab564ef9aaaa640adf2a9");
array.findOneAndUpdate
(
    { '_id' : o_id    },
    {$set:{ user:['$user','Helooword']}}, //output:"user":"$user,heeeeeeeeo",
    function (error, success) 
    {
        if (error) console.log(error);
        if(success == null )
            console.log("nullllllllllllllllllllllll");
        console.log(success);
    }
);
Moh_beh
  • 251
  • 1
  • 3
  • 14

1 Answers1

0

For now, the answer is you can't do this in a findOneAndUpdate.

See this question for other options/ideas.

SwampBuck
  • 61
  • 3