简体   繁体   English

Perl MongoDb多个更新

[英]Perl MongoDb multiple update

i want to update all records in my database(mongodb),I tried to use command below to do that but I could not reach the solution. 我想更新数据库(mongodb)中的所有记录,我尝试使用下面的命令来执行此操作,但我无法达到解决方案。

use MongoDB;
my $dbhost = MongoDB::Connection->new(host => '127.0.0.1', port => 27017);
    my $database   = $dbhost->test;
my $res = $database->questions;
$res->update({'person'=>'omer'},{'$set' => { 'canbeseen' =>"oha"}},{"multi" => "true"} );

i want to update all omer's "canbeseen"s. 我想更新所有omer的“ canbeseen”。 but it isn't working, so how can i do that? 但是它不起作用,那我该怎么办呢? i'm waiting for your answers. 我在等你的答案。 thank you. 谢谢。

The MongoDB module seems to use the multiple keyword instead of multi : MongoDB模块似乎使用multiple关键字而不是multi

$res->update(
  {'person'   => 'omer' },
  {'$set'     => { 'canbeseen' => "oha" } },
  {'multiple' => "true" }
);

From the documentation : 文档中

multiple All of the documents that match $criteria will be updated, not just the first document found. multiple匹配$ criteria的所有文档都将更新,而不仅仅是找到的第一个文档。 (Only available with database version 1.1.3 and newer.) (仅适用于数据库版本1.1.3和更高版本。)

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

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