Answer the question
In order to leave comments, you need to log in
How to change object in mongodb collection?
Hello everyone)
Suppose there is a user object, and an array of objects in the profile.
var user = {
_id:1
profile:{admin:false,
subscriptions:[
{id:1, name:'name1'}, {id:2, 'name:2'}
]}
}
db.users.update(
{
"_id" : 1,
"suscriptions.id" : 1
},
{
$set :
{
"suscriptions.$" : {
"name" : "new name",
}
}
}
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question