adding data in fields of a single document in mongodb -


i have data:

_id : 1 status:1,  name:"name", details: {    crm:115,    webs:      { tag:"blog" , url:"http://..."},    contacts:     {       _id:1,       name:"me",        phones:         { tag:"home", number:"123..." },         {tag:"mobile", number:"123456789"}     } } 

i want 1 more entry in "phones" {tag:office", number:"9823..."}

what command/query that?

you can push array following query (i had modify json pasted, not valid little):

db.collection.drop(); db.collection.insert( {     _id : 1,     status: 1,      name: "name",     details: {          crm:115,            webs: {             tag:"blog",             url:"http://..."         },          contacts: {             _id: 1,             name: "me",              phones: [                 { tag: "home", number: "123..." },                 { tag:"mobile", number:"123456789" }             ]         }     } } );  db.collection.update(     { _id: 1 },     { $push : { 'details.contacts.phones' : {  tag:"office", rname:"9823" } } } );  db.collection.find().pretty(); {     "_id" : 1,     "details" : {     "contacts" : {         "_id" : 1,         "name" : "me",         "phones" : [             {                 "tag" : "home",                 "number" : "123..."             },             {                 "tag" : "mobile",                 "number" : "123456789"             },             {                 "tag" : "office",                 "rname" : "9823"             }         ]         },         "crm" : 115,         "webs" : {         "tag" : "blog",         "url" : "http://..."         }     },     "name" : "name",     "status" : 1 } 

Comments