-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 4.4.9, 7.0.11, 8.0.12
-
Component/s: Query Execution
-
None
-
Query Execution
-
ALL
-
-
None
-
3
-
TBD
-
None
-
None
-
None
-
None
-
None
-
None
-
None
MongoDB leaves a server-side cursor open (returning a non-zero cursor ID) when all the following conditions are met:
- A find command is issued with limit and batchSize set to the same value.
- The query requires an in-memory sort stage (i.e., explain() output shows hasSortStage: true).
- The number of documents returned (nreturned) equals the limit.
Expected Behavior:
The server should automatically close the cursor, since the query's limit has been fully satisfied.
Actual Behavior:
A cursor is opened on the server and its ID is returned to the client. This is unexpected and requires clients to explicitly kill the cursor for a query they would assume is complete. If the cursor is not explicitly closed, it remains active on the server until it times out or the client disconnects, causing a resource leak.