Reputation: 663
My mongodb document is
{
"_id" : {
"coid" : "testcoid",
"cid" : "testcid"
},
"communications" : [
{
"sid" : "testsid",
"campid" : "testcampid"
}
]
}
I want to finally add clicks field and add multiple values
{
"_id" : {
"coid" : "testcoid",
"cid" : "testcid"
},
"communications" : [
{
"sid" : "testsid",
"campid" : "testcampid",
"clicks" : {"www.google.com" , "www.facebook.com"}
}
]
}
I am using command
db.messages.update({$and : [{"_id.coid" : "testcoid"}, {"communications.sid" : "testsid"}]},{ $push : {"communications.$.clicks" : {$each : ["www.google.com" , "www.facebook.com"]}}})
which instead gives this document
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 it with push itself not pushAll. Is there a way to do it with push and why is it updating it with $each object?
Upvotes: 4
Views: 758
Reputation: 3366
Your query worked on my box, http://pastebin.com/STUjCuMd
Which mongodb version you are using?
Check this : https://jira.mongodb.org/browse/SERVER-8303
Upvotes: 2