如何更新 mongodb PHP 中的所有文档 [英] How do I update all documents in mongodb PHP
本文介绍了如何更新 mongodb PHP 中的所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设置一个 cronjob 来更新集合 query
中所有文档的字段 views_15
.
I am setting up a cronjob to update the field views_15
on all documents from collection query
.
这就是我所拥有的,应该有效:
This is what I had, that should have worked:
$update = array(
'$set' => array (
'views_15' => 0
)
);
$db->queries->update(array(), $update, array('multi' => true));
它也适用于特定查询!
那么我应该使用什么来代替 array()
,来自 <查询 > 参数选择所有文档?
So what should I use instead of array()
, from the < query > parameter to select all documents?
推荐答案
在更新命令的选项中将 'multi'
替换为 'multiple'
:
Replace 'multi'
with 'multiple'
in the options to your update command:
$db->queries->update(array(), $update, array('multiple' => true));
参见 http://php.net/manual/en/mongocollection.update.php所有有效的更新选项.
See http://php.net/manual/en/mongocollection.update.php for all the valid update options.
这篇关于如何更新 mongodb PHP 中的所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文