gpt4 book ai didi

mongodb - jenssegers/laravel-mongodb 中的 MongoCursorTimeoutException

转载 作者:IT老高 更新时间:2023-10-28 13:16:53 24 4
gpt4 key购买 nike

我有一个查询,它在一个庞大的集合(超过 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com