php - MongoDB update sub document issue -


i'm having mongo structure this,

"campaigns":[{     "summary" :        [ {         "postcode" : [ {                         "id" : "71",                        "name" : "recall 1",                         "qty" : 3,                         "history" :                              [ { "timestamp" : "2014-12-16 11:15:32",                                { "timestamp":  "2014-12-16 11:15:53"                             } ]                         } ]       },      {      "postcode" :             [ {                      "id" : "72",                  "name" : "recall 2",                  "qty" : 1,                 "history" : [ { "timestamp" : "2014-12-16 11:15:53" } ]             } ]    }] 

i'm trying i) increment qty of postcode.id : 72 ii) insert timestamp same postcode id 72.

my code:

    $collection->update(array("campaigns.task.id" => $b,"_id"=> new mongoid($objectid),"campaigns.0.summary.0.postcode.0.id" => $a), array('$inc' =>  array('campaigns.0.summary.0.postcode.0.qty' => 1)));     $collection->update(array("campaigns.task.id" => $b,"_id"=>new mongoid($objectid),"campaigns.0.summary.0.postcode.0.id" => $a),  array('$addtoset' =>  array('campaigns.0.summary.0.postcode.0.history' => array("timestamp"=>$now->format('y-m-d h:i:s'))))); 

but postcode.id = 72 not gets updated, i'm confused nested subdocument can suggest me solution ?


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -