Adding new element to array in MongoDb -


i have mongodb collection this:-

{     "_id": objectid("52174bcb834806830e5447"),     "roles": [         {             "role": "admin"         },         {             "role": "user"         }     ] } 

i need add new 'role' roles array. {"role": "guest" }. how do that?

you can $push-operator

this should work:

 db.collection.update(      { _id:  objectid("52174bcb834806830e5447") },      { $push: { roles: { role: "guest" } } }  ); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -