Answers for "mongodb add property to object inside array"

0

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})
Posted by: Guest on February-25-2021

Code answers related to "mongodb add property to object inside array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language