duanliusong6395 2015-01-05 03:34
浏览 84

在同一个集合上更新时mongo游标会受到影响吗?

I have some code like following,

$query = array("vid"=>"just_a_video_key_and_can_be_any_string");
$set = array("$set" => array("attr" => "attr_value"));
$cursor = $collection->find();
$cursor = $cursor->batchSize(500);
foreach ($cursor as $item) {
    $collection->update($query, $set)
}

I find the loop times is 500, while the $collection has 20K+ documents.

The update operation only update one document, not involving delete or insert.

My question is why the foreach loop only 500 times(which is the number of batch size) while the total documents in the database is more than 20K?

  • 写回答

3条回答 默认 最新

  • duanruinong0619 2015-01-05 07:43
    关注

    If I'm understanding you correctly, you're confused about why mongodb is only updating one document.

    Mongodb only updates one document at a time. To update all documents which match your query, pass the multiple option to mongodb via 'multiple' => true. See https://stackoverflow.com/a/15691466/2416049

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘