I have an array that contains objects of users, like below.
[
{id: 122, name: 'Jone', addr: '11111aaaa'},
{id: 12, name: 'Jane', addr: 'spring field'},
{id: 14, name: 'Joe', addr: 'awesome street'},
]
When each user is saved to a separated document, is there any way that I can update the user's address at once? Or do I just have to do the loop?
CodePudding user response:
Use multi update ?
db.collection.update({
name: {
$in: [
"Jone",
"Jane"
]
}
},
{
$set: {
addr: "somewhere"
}
},
{
multi: true
})