Php MongoDB更新子文档发布
我有这样的Mongo结构Php MongoDB更新子文档发布,php,mongodb,yii,Php,Mongodb,Yii,我有这样的Mongo结构 "campaigns":[{ "summary" : [ { "postcode" : [ { "id" : "71", "name" : "Recall 1", "qty" : 3, "history" :
"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)增加邮政编码的数量。id:72 ii)为相同的邮政编码id 72插入另一个时间戳
我的代码:
$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')))));
但是postcode.id=72未更新,我对这个嵌套子文档感到困惑。有人能给我建议解决方案吗?您的文档格式不正确。例如,
“postcode.id”:72中历史数组中的第一个对象中发生了什么?你能发布一个完整的、格式良好的MongoDB文档吗?然后,如果可能的话,我将制定查询来修改您想要的内容。