简体   繁体   English

如何更新mongodb PHP中的所有文档

[英]How do I update all documents in mongodb PHP

I am setting up a cronjob to update the field views_15 on all documents from collection query . 我正在设置一个cronjob来更新来自集合query所有文档的views_15字段。

This is what I had, that should have worked: 这就是我所拥有的,应该有效:

    $update = array(
        '$set' => array (
            'views_15' => 0
            )
    );

    $db->queries->update(array(), $update, array('multi' => true));

Also it works for a specific query! 它也适用于特定的查询!

So what should I use instead of array() , from the < query > parameter to select all documents? 那么我应该使用什么而不是array() ,从<query>参数中选择所有文档?

Replace 'multi' with 'multiple' in the options to your update command: 在更新命令的选项中将'multi'替换为'multiple'

$db->queries->update(array(), $update, array('multiple' => true));

See http://php.net/manual/en/mongocollection.update.php for all the valid update options. 有关所有有效的更新选项,请参见http://php.net/manual/en/mongocollection.update.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM