50: MaxTimeMSExpired (error code 50)
MongoDBWhat does it mean?
The server canceled the operation because it exceeded the time limit set with maxTimeMS. The query did not complete within the allotted time.
Why does it happen?
Long-running queries, collection scans (COLLSCAN) caused by missing indexes, large data volumes, heavy aggregation operations or high server load.
How to fix it
Optimize the query: inspect the plan with explain() and add an appropriate index. If more time is genuinely needed, increase maxTimeMS. Simplify heavy aggregations or filter early with $match. Split results with pagination. Check server load and resource capacity.