PHP MongoDB update multiple documents using $in/$or

随声附和 提交于 2019-12-10 14:42:35

问题


I'm having trouble figuring out how to construct an update query in PHP that will update document IDs X,Y, and Z. Does anyone have experience with this?

$ids[] = array(
  new MongoId('4eaaf929498fe2c80300000c'),
  new MongoId('4eaaff24498fe2ba0900001f')
); 
$collection->update(
  array('_id' => array('$in' => $ids)),
  array('$set' => array("title"=>"test")),
  array("upsert" => true)
);

回答1:


I assume that your trouble is, that only one document get's updated, right? If this is the case, there is another setting you have to specifiy in the third parameter (the options parameter) for the update method:

multiple => true

Otherwise, it will only update the first match of your query. See the documentation to the update method at:

http://de.php.net/manual/en/mongocollection.update.php



来源:https://stackoverflow.com/questions/7934119/php-mongodb-update-multiple-documents-using-in-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!