mongodb - Push an array of documents embedded in a document -


i have collection in following format

{name: "asd", age: 23} 

i want add array of documents such final collection looks like

{     name: "asd",      age: 23,      address: [         {city: "tokyo", country: "japan"},         {city: "beijing", country: "china"}     ] } 

tried following code in pymongo

db.collection.update({name:"asd", age:23},{"$push":{"address":{"city:"tokyo",country:"japan"}}},upsert=true) 

receiving following error:

the field 'address' must array of type object in document

i see there typo in query:

{"city:"tokyo",country:"japan"}

following update works in mongo shell:

db.collection.update( {name: "asd", age: 23}, {$push:{ "address":{"city":"tokyo",country:"japan"} }}, {upsert:true}) 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -