How can I avoid MongoCursorTimeoutException in /db/mongo/mapper.php

115 views
Skip to first unread message

Muhammad Shahzad

unread,
Jan 4, 2018, 1:57:03 AM1/4/18
to Fat-Free Framework
Hi,

I'm facing this issue "MongoCursorTimeoutException", what should I do to avoid this exception, pls suggest a best solution as I have more than 3 million records in mongodb whenever I performed aggregation it returns this error:


Uncaught Exception: Uncaught exception 'MongoCursorTimeoutException' with message '5645xyz:27017: Read timed out after reading 0 bytes, waited for 30.000000 seconds' in /var/www/vhosts/example.com/f3app/lib/db/mongo/mapper.php:149


Stack trace

…hosts/example.com/f3app/lib/db/mongo/mapper.php(149): MongoCollection->group(Array, Array, 'function(obj,re...', Array)
…hosts/example.com/f3app/lib/db/mongo/mapper.php(223): DB\Mongo\Mapper->select(NULL, Array, Array, 0)
…www/vhosts/example.com/f3app/cron/savestats.php(456): DB\Mongo\Mapper->find(Array, Array)
{main}

savestats.php
require_once "base.php";$mapper = new \DB\Mongo\Mapper($f3->get('MongoDB'), 'transactions');#Top 12 stores$group3 = [            'keys'=>['storeId'=>1],            'initial'=>['count'=>0],            'reduce'=>'function(obj,result){                                       if(typeof obj.store !="undefined"){                       result.count++;                       result.storeName = obj.store.name;                    }                                }',            'finalize'=>'function(result){}',    ];$result3 = $mapper->find($filters, ['group'=>$group3]);

ikkez

unread,
Jan 4, 2018, 6:32:19 AM1/4/18
to Fat-Free Framework
So the error appeared as the database has grown? Or is the query failing in general?
When it's just because of the size, you can try to raise the query timeout, to wait longer for the result. Call one of this before you make the query:

\MongoCursor::$timeout = -1; // wait infinitely
\MongoCursor::$timeout = 60; // wait 60 seconds

Muhammad Shahzad

unread,
Jan 4, 2018, 7:00:21 AM1/4/18
to Fat-Free Framework
Hi,

Where should I use this timeout option?

before this code?

$result3 = $mapper->find($filters, ['group'=>$group3]);

ikkez

unread,
Jan 4, 2018, 9:31:32 AM1/4/18
to Fat-Free Framework
yes
Reply all
Reply to author
Forward
0 new messages