MongoCursorTimeoutException in jenssegers / laravel-mongodb

I have a query that searches for data in a huge collection (over 48 M), but even if I add timeout=-1 to it, it still throws a 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(); 

I use this library: https://github.com/jenssegers/laravel-mongodb

Any ideas?

+8
mongodb laravel
source share
1 answer

There is a problem with PHP-1249 - MongoCursor :: count () should use the cursor socket timeout provided for PHP MongoDB driver v1.5.7, which was fixed in version 1.5.8 in October 2014.

answer from support:

maxTimeMS looked at the code a bit, it seems that both the socket timeout and maxTimeMS not transmitted along with the count command.

If you need immediate work, you can go through with MongoDB::command() (which can support both timeouts).

Workaround sent by one of the users:

 $countComand = $mongo->command( array( 'count' => 'collection', 'query' => $query ), array('socketTimeoutMS' => -1) ); if($countComand['ok']){ $count = $countComand['n']; } else { // ... error ... } 

It seems that laravel-mongodb is not using MongoDB::command() . You must either explicitly write your request without the help of the where methods, as shown above, or upgrade to v.1.5.8.

+1
source share

All Articles