Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行时错误:MongoDB::DatabaseError:错误提示_Mongodb_Perl - Fatal编程技术网

运行时错误:MongoDB::DatabaseError:错误提示

运行时错误:MongoDB::DatabaseError:错误提示,mongodb,perl,Mongodb,Perl,我正试着打电话给警察。但是,它在尝试执行查询时会引发异常。请参见下面的代码示例: sub some_method_which_returns_cursor { my $cursor = $collection->find($filter); if ($hint) { $cursor->hint({‘some_index’ => 1}); #failing here. } if ($sort) { $cursor->sort($sor

我正试着打电话给警察。但是,它在尝试执行查询时会引发异常。请参见下面的代码示例:

sub some_method_which_returns_cursor {

  my $cursor = $collection->find($filter);

  if ($hint) {
    $cursor->hint({‘some_index’ => 1});  #failing here.
  }

  if ($sort) {
    $cursor->sort($sort);
  }

   return $cursor;
}

关于发生了什么以及我如何解决这个问题,你有什么想法吗?

哈里什通过电子邮件问我,我将在这里为子孙后代重复我的回答:

hint
方法在给定索引名时采用字符串,或在给定键/顺序对时采用数组引用:

$cursor->hint("some_index");                # by name
$cursor->hint([field1 => 1, field2 => -1]); # by keys

它还需要一个散列引用,但不要使用它,因为现代PERL在序列化时会随机化键顺序,因此您的提示可能与索引不匹配。

这是您的真实代码吗?无效:
$cursor->hint({some_index=>1})不要在程序中使用“and”作为引号。或者,换言之,不要使用文字处理器编写程序。还有,如果
,什么是
?!语句后定义了什么或(即,
/
)在做什么@Borodin
ghd
显然是我键入
的方式。顺便说一句,这在MongoDB perl驱动程序版本0.45上不起作用。但在v1.8.0上也可以使用@xdg