Clarification regarding working of maxTimeMS options

Hi @Naveen_Kumar10 - Welcome to the community.

My doubt is that whether maxtimeMS is applicable for the entire cursor iterations(whole find operation) or else for single cursor iteration. Need some help on this.

For the cursor.maxTimeMS(), queries that generate multiple batches of results continue to return batches until the cursor exceeds its allotted time limit. maxTimeMS() relates to processing time (not the cursor’s idle time). The maxTimeMS() would be applicable to the whole cursor. E.g. If you have 10 batches for a particular operation and the 4th batch’s cumulative processing time exceeds the maxTimeMS() configured, the operation would terminate (1st + 2nd + 3rd + 4th processing time > maxTimeMS() configured value).

You can see an error message in the logs (if configured to log these details) somewhat similar to the below depending on your MongoDB version:

..."msg":"getMore command executor error","attr":{"error":
{"code":50,"codeName":"MaxTimeMSExpired","errmsg":"operation exceeded time limit"}

Please note that Session Idle Timeout Overrides maxTimeMS.

Regards,
Jason

4 Likes