My mongodb document
{ "_id" : { "coid" : "testcoid", "cid" : "testcid" }, "communications" : [ { "sid" : "testsid", "campid" : "testcampid" } ] }
I want to finally add a click field and add some values
{ "_id" : { "coid" : "testcoid", "cid" : "testcid" }, "communications" : [ { "sid" : "testsid", "campid" : "testcampid", "clicks" : {"www.google.com" , "www.facebook.com"} } ] }
I use the command
db.messages.update({$and : [{"_id.coid" : "testcoid"}, {"communications.sid" : "testsid"}]},{ $push : {"communications.$.clicks" : {$each : ["www.google.com" , "www.facebook.com"]}}})
which gives this document instead
db.messages.find().pretty() { "_id" : { "coid" : "testcoid", "cid" : "testcid" }, "communications" : [ { "campid" : "testcampid", "clicks" : [ { "$each" : [ "www.google1.com", "www.google2.com" ] } ], "sid" : "testsid" } ] }
Note. I need to do this using push, not pushAll. Is there a way to do this with push and why does it update it with $ of each object?
source share