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
Post a Comment