push array within array within array(collection) in mongodb using php -
i have collection in mongodb called job
job{ _id : ‘12344’, cust_id: 'cust1', title: 'create website', description: 'we require in 2 weeks only', location: 'japan', images:{ 'image1', 'image2', 'image3' }, video:{ 'video1', 'video2' }, budget:'15000', duration:'2 weeks', proposals:[{ "sender_id" => "5", "description" =>"i can task before 2 week", "date" => "2013-08-05" }, { "sender_id" => "6", "description" =>"i can task in 2 week, best quality", "date" => "2013-08-05" } ] }
i want add messages in proposal attributes sender_id=5 below;
job{ _id : ‘12344’, cust_id: 'cust1', title: 'create website', description: 'we require in 2 weeks only', location: 'japan', images:{ 'image1', 'image2', 'image3' }, video:{ 'video1', 'video2' }, budget:'15000', duration:'2 weeks', proposals:[{ "sender_id" => "5", "description" =>"i can task before 2 week", "date" => "2013-08-05" “messages”:[{ "message_sender" :"can meet", "date" : "2013-08-06" } ] }, { "sender_id" => "6", "description" =>"i can task in 2 week, best quality", "date" => "2013-08-05" } ] }
my document is,
$document = array( "message_sender" =>"can meet", "date" => "2013-08-06" );
i having hard time doing thing. add messages proposal array. out there php code?
this perfect answer work me,
db.jobs.update({"_id" : "12344","proposals.sender_id":"5"},{$push:{"proposals.$.messages" : { "message" : "can meet" , "date":"2013-08-06"}}})
Comments
Post a Comment