-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Query Operations
The current implementation of the first() method in MongoIterableImpl creates a BatchCursor and calls the next() method to retrieve only the first entry. However, underlying readOperation is created with the batch size specified by the user. As a result, a call to the server is made to retrieve documents in batches, even though only the first element is returned by the first() method.
It leads to inefficient utilization of system resources, including heap memory, and places undue pressure on the server and network. To resolve this issue, it is recommended to optimize the first() method by ensuring that the readOperation is created with a batch size of 1.