Clarification regarding working of maxTimeMS options

Hi ,

I want some understanding regarding the working of maxTimeMS option in Cursor /find / aggregate…

From my understanding, find operation will internally have some deafult batch size associated with it, hence, if we fire some find query it will fetch and return the result in batches, if the result document exceeds the default batch size. [ For eg., lets say default batch size = 10 and result size = 100, then the find query internally return the results in 10 iterations (10 batches)]

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. I referred the documentation, can’t able to get clarity. Can anyone able to help me on this one?

I want to configure maxTimeMS for my queries in my project, hence thought of getting good clarity before using it.

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

3 Likes

Thanks for the detailed explanation @Jason_Tran . Now I got a clear understanding.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.