Answer the question
In order to leave comments, you need to log in
How to replace/update an object in an array?
Hello. Tell me, there is a MongoDB collection, documents with the following structure:
{
name:'Bob',
items:[{
id:12
name:'...',
lastName:'..'
},
{
id:13
name:'...',
lastName:'..'
}]
}
Model.update({ 'items.id': id }, {$set:{
'items.$[element]':obj,
}}, {multi:true}, function(err, doc){
console.log('doc', doc);
});
Answer the question
In order to leave comments, you need to log in
On vanilla js, but the logic should somehow be the same
(currdat = "plus",
data = {name:"major",items:[{id:12,name:'extra'},
{id:13,name:'basic'}]},
function(param=12)
{return data.items[0].id==12?data.items[0].name=currdat:"not found"}()
)
//вернет "plus"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question