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