mongodb add field to object in array code example
Example: mongodb add property to object inside array
//Example "users" collection:
{
name: "Jim",
friends: [
{name: "Pam"},
{name: "Michael"}
]
}
//Will be:
{
name: "Jim",
friends: [
{name: "Pam", active: true},
{name: "Michael", active: true}
]
}
//For every user inside "users"
db.getCollection('users').update({}, {"$set": {"friends.$[].active": true}}, {multi: true})