-
Type: New Feature
-
Resolution: Won't Fix
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Cursors
Our AbstractCursor iterator helper methods return `null` to indicate that the cursor has been completely iterated. However, using `null` to indicate the "lack of another value" is problematic in the case where a user may want to map values to `null` because after mapping a value to `null`, we perceive the cursor as being exhausted and close it.
See NODE-4609 as a recent bug report about this behavior.
If our internal `next` helpers returned documents that conformed to the `iterator` protocol (documentation here) we could allow users to map to `null` values.
Acceptance Criteria
- Refactor the internal `next` method to return an iterator object instead of the raw document result.
- Update our `Symbol.asyncIterator` implementation to call next directly and use the `done` property to determine when the cursor is exhausted instead of relying on the cursor returning a `null` value
- Refactor `cursor.next`, `cursor.tryNext` and `cursor.hasNext` to unwrap the iterator object returned from `next` and return the value