-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
Use Case
See https://mongodb.slack.com/archives/C72LB5RPV/p1729101189007139.
Shane pointed out recently that the logic for findOne sets a batch size of 1 that isn't needed:
const cursor = this.find(filter, options).limit(-1).batchSize(1); const res = await cursor.next(); await cursor.close(); return res;
This has no impact on the command built - because a `limit = -1` sets `singleBatch` to true on the find command with a `limit=1`. Other drivers don't set a batch size in this scenario, we could remove it for clarify and consistency with other drivers.
While we're here, we should omit `batchSize` as a FindOption, because we expect a single batch with only one document at most.
User Experience
n/a
Dependencies
n/a
Risks/Unknowns
n/a
Acceptance Criteria
Implementation Requirements
Omit batchSize as an option to findOne.
Don't set batchSize on the cursor before executing the find.
Testing Requirements
- unit test, spec test sync, etc
Documentation Requirements
- DOCSP ticket, API docs, etc
Follow Up Requirements
- additional tickets to file, required releases, etc
- if node behavior differs/will differ from other drivers, confirm with dbx devs what standard to aim for and what plan, if any, exists to reconcile the diverging behavior moving forward
- duplicates
-
DRIVERS-3009 Ensure findOne does not set batchSize=1
- Implementing
- related to
-
SERVER-82274 singleBatch find on a timeseries collection does not close cursor if batchSize is set
- Closed