-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Performance
Use Case
As a Node.js driver user performing using toArray on my cursors
I want to lower the cost of iterating through each document
So that I can get better performance from the API
This optimization exists in v3:
https://github.com/mongodb/node-mongodb-native/blob/v3.7.4/lib/cursor.js#L861-L864
User Impact
- Performance improvement
Dependencies
- All cursor usages but no functional change
Unknowns
- Internally representing the change in Typescript (can't remember what was meant by this)
Acceptance Criteria
Implementation Requirements
- Update toArray to:
- consume entire batches as they arrive
- use arrays returned from BSON to extend the local array being built
- toArray can apply document transformations to the final array if a transform was given
Testing Requirements
- Sinon spy assert next is called less than # of documents
Additional Verification
- While working with the toArray and findManyAndExhaustCursor benchmarks. Change batchSize to NOT default to 1000, and rather remain unset. Document the change in results here, and file a follow up ticket in the Node v7 epic to consider changing that default.
Documentation Requirements
- None
Follow Up Requirements
- None