I have a query which looks up data in a huge collection (over 48M), yet even if I add timeout=-1
to it, it still throws 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();
I am using this library: https://github.com/jenssegers/laravel-mongodb
Any ideas?
There is an issue PHP-1249 - MongoCursor::count() should use cursor's socket timeout submitted for PHP MongoDB driver v1.5.7 which was fixed in v1.5.8 in October, 2014.
The reply from the support:
Looking into the code a bit, it appears that both socket timeout and
maxTimeMS
is not passed along to thecount
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).
The workaround posted by one of the users is:
$countComand = $mongo->command(
array(
'count' => 'collection',
'query' => $query
),
array('socketTimeoutMS' => -1)
);
if($countComand['ok']){
$count = $countComand['n'];
} else {
// ... error ...
}
It seems that laravel-mongodb doesn't use MongoDB::command()
. You either have to write your query explicitly without help of where
methods as shown above or upgrade to v.1.5.8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With