You can update the embedded sales document inside the act_mgr array with the following update statement:
> db.sales.update({"act_mgr.sales.last_interacted":"rohan@walkover.in"}, {$push:{"act_mgr.$.sales.agent":"abc@walkover.in"}, $set:{"act_mgr.$.sales.last_interacted":"abc@walkover.in"}})
> db.sales.find().pretty()
{
"_id" : ObjectId("4f855061dd53351011000b42"),
"act_mgr" : [
{
"sales" : {
"agent" : [
"rohan@walkover.in",
"abc@walkover.in"
],
"last_interacted" : "abc@walkover.in"
}
}
],
"email" : "aman@asasas.com",
"name" : "Aman",
"sales" : [
{
"sno" : 1,
"message" : "description",
"status" : "open"
},
{
"sno" : 12,
"message" : "assad",
"status" : "open"
}
]
}
>
You can add an embedded document containing information about the "developer" into the array as follows:
> db.sales.update({"_id" : ObjectId("4f855061dd53351011000b42")}, {$push:{"act_mgr":{ "developer" : {"agent" : ["newdeveloper@walkover.in" ], "last_interacted" : "newdeveloper@walkover.in" } }}})
> db.sales.find().pretty()
{
"_id" : ObjectId("4f855061dd53351011000b42"),
"act_mgr" : [
{
"sales" : {
"agent" : [
"rohan@walkover.in",
"abc@walkover.in"
],
"last_interacted" : "abc@walkover.in"
}
},
{
"developer" : {
"agent" : [
"newdeveloper@walkover.in"
],
"last_interacted" : "newdeveloper@walkover.in"
}
}
],
"email" : "aman@asasas.com",
"name" : "Aman",
"sales" : [
{
"sno" : 1,
"message" : "description",
"status" : "open"
},
{
"sno" : 12,
"message" : "assad",
"status" : "open"
}
]
}
>
$push $set "":
http://www.mongodb.org/display/DOCS/Updating
Mongo db " ( )"
http://www.mongodb.org/display/DOCS/Dot+Notation+%28Reaching+into+Objects%29
"$" " $positional" "".
http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator
: , . . , "sno", "message" "status"
"act_mgr" ; "", "". , , :
"act_mgr" : [
{
"title" : "sales",
"agent" : [
"rohan@walkover.in",
"abc@walkover.in"
],
"last_interacted" : "abc@walkover.in"
},
{
"title": "developer",
"agent" : [
"newdeveloper@walkover.in"
],
"last_interacted" : "newdeveloper@walkover.in"
}
]
, "title", "agent" "last_interacted".
.
> db.sales.update({"act_mgr.title":"sales"}, {$push:{"act_mgr.$.agent":"abc@walkover.in"}, $set:{"act_mgr.$.last_interacted":"abc@walkover.in"}})
, , , . !