带PHP驱动程序的MongoDB-如何通过一个更新查询推送到多个数组?

带PHP驱动程序的MongoDB-如何通过一个更新查询推送到多个数组?,php,mongodb,mongodb-query,Php,Mongodb,Mongodb Query,我想用一个PHP中的MongoDB更新查询推到同一文档中包含的多个数组。我尝试了以下两个电话,但均未成功: //this one causes php run error $collection->update(array("scienceNumber"=>$scienceNumber), array('$push'=>array(array("comments"=> $comment), array("ids"=> $userID), array("time

我想用一个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)
);

这就成功了。我愚蠢地错过了一件显而易见的事情。谢谢你指出这一点。