我有一个查询在一个巨大的集合中查找数据(超过48M),但即使我添加timeout=-1
它,它仍然抛出MongoCursorTimeoutException
异常..
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();
Run Code Online (Sandbox Code Playgroud)
我正在使用这个库: https://github.com/jenssegers/laravel-mongodb
有任何想法吗?
有一个问题PHP-1249 - MongoCursor::count() 应使用为 PHP MongoDB 驱动程序 v1.5.7 提交的游标套接字超时,该问题已于 2014 年 10 月在 v1.5.8 中修复。
来自支持的回复:
稍微查看一下代码,似乎套接字超时并且
maxTimeMS
没有传递给count
命令。
MongoDB::command()
如果您需要立即解决方法,那么您现在应该能够应付(可以支持两种超时)。
其中一位用户发布的解决方法是:
$countComand = $mongo->command(
array(
'count' => 'collection',
'query' => $query
),
array('socketTimeoutMS' => -1)
);
if($countComand['ok']){
$count = $countComand['n'];
} else {
// ... error ...
}
Run Code Online (Sandbox Code Playgroud)
看来laravel-mongodb不使用MongoDB::command()
. 您要么必须在没有where
上述方法帮助的情况下显式编写查询,要么升级到 v.1.5.8。
归档时间: |
|
查看次数: |
964 次 |
最近记录: |