hwo to add an element to an array of a property in mongodbb 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})