"Server x timeout" during MongoDB aggregation

I have a script that periodically runs aggregation in the mongodb collection. As the data set grows, the time spent on aggregation increases. My script aggregation recently stopped working sequentially, and the error logs show: error: { [MongoError: server <x> timed out] name: 'MongoError', message: 'server <x> timed out' } I tried to debug this, and the only one the pattern I can find is that this timeout seems to occur only when the aggregation takes more than 2 minutes (turnaround time about 2 m). Anyone have any further debugging tips? The 2 minute thing gives me the impression that I just need to set some kind of timeout somewhere, but I can't figure out where or if I just fall into a trap with a red herring.

About the system configuration: this is an aggregation script - this is the node.js application (v5.9.1) running in the docker container (v1.9.1) in the Alpine language. It uses the mongodb node driver (v2.1.19). One mongodb server (although this also happens in a separate environment using replSet) working with mongod (v3.2.6)

+6
source share
1 answer

I have the same problem for log time aggregation. I think I have a solution for you.

I found that the socketTimeoutMS option is responsible for this. Check the default socketTimeoutMS . For me it was 2min . Mongodb module version 2.1.18.

So just add this parameter to your URL:

 mongodb://localhost:27017/test?maxPoolSize=2&socketTimeoutMS=60000 

It will set the timeout in 10 minutes. It does the trick for me.

+5
source

All Articles