mongodb - jenssegers/laravel-mongodb 中的 MongoCurso

我有一个查询,它在一个庞大的集合(超过 48M)中查找数据,但即使我添加 timeout=-1 到它,它仍然会抛出 MongoCursorTimeoutException异常(exception)..

return \DB::connection('mongodb')->collection('stats')->timeout(-1)
    ->where('ip','=',$alias)
    ->where('created_at','>=', new \DateTime( $date ) )
    ->where('created_at','<=', new \DateTime( $date . ' 23:59:59' ) )
    ->count();

我正在使用这个库:https://github.com/jenssegers/laravel-mongodb

有什么想法吗?

最佳答案

有一个问题PHP-1249 - MongoCursor::count() should use cursor's socket timeout为 PHP MongoDB 驱动程序 v1.5.7 提交,已于 2014 年 10 月在 v1.5.8 中修复。

reply来自支持:

Looking into the code a bit, it appears that both socket timeout and maxTimeMS is not passed along to the count command.

If you need an immediate work-around, you should be able to get by with MongoDB::command() for now (which can support both timeouts).

其中一位用户发布的解决方法是:

$countComand = $mongo->command(
    array(
        'count' => 'collection',
        'query' => $query
    ),
    array('socketTimeoutMS' => -1)
);

 
if($countComand['ok']){
    $count = $countComand['n'];
} else {
    // ... error ...
}

看来laravel-mongodb不使用 MongoDB::command()。您要么必须在没有 where 方法帮助的情况下显式编写查询,如上所示,要么升级到 v.1.5.8。

关于mongodb - jenssegers/laravel-mongodb 中的 MongoCursorTimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31190504/

相关文章:

python - Mongo 连接从未发布 - Django 和 Mongoengine 使用 ge

mongodb - 一个集合中的许多文档与多个集合

mongodb - Mongorestore:ns 名称太长,最大大小为 128

node.js - 如何使用一个属性的值作为另一个属性的默认值?

javascript - 使用 Javascript/Node.js 在代码中执行 mongoimp

node.js - MongoError : attempt to write outside bu

mongodb - MongoDB中的有向无环图设计模式

php - 如何安装 PHP 的 MongoDB 驱动程序 — "pecl install mong

mongodb - 通过 Grails 域标准在事件光标中发现 Mongo CursorNotFou

node.js - 2服务器负载均衡 Node js应用设置中的Elasticsearch部署