MongoDB与PHP驱动程序-如何推到多个数组与一个更新查询


MongoDB with PHP driver - how to push onto multiple arrays with one update query?

我想在PHP中使用单个MongoDB更新查询推送到同一文档中包含的多个数组。我打了以下两个电话都没有成功:

 //this one causes php run error
 $collection->update(array("scienceNumber"=>$scienceNumber),  array('$push'=>array(array("comments"=> $comment), array("ids"=> $userID), array("times"=> $time))), array("upsert"=>true));
 //this one runs a query but only pushes $time onto the times array, ignoring the other push instructions
 //that outcome totally makes sense since I am assigning all these different arrays to the same key...no complaints...but then the above didn't work either
 $collection->update(array("scienceNumber"=>$scienceNumber), array('$push'=>array("comments"=> $comment), '$push'=>array("ids"=> $userID), '$push'=>array("times"=> $time) ), array("upsert"=>true));

那么如何在一个更新查询中完成呢?

我也意识到我可以通过拥有一个文档数组并将所有值存储在一起来实现这一点,但这会使后面的其他查询更加麻烦。

这个呢:

$collection->update(
    array("scienceNumber"=>$scienceNumber),   
    array('$push'=>array("comments"=> $comment, "ids"=> $userID, "times"=> $time)),
    array("upsert"=>true)
);