-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.12.1
-
Component/s: Cursors
What problem are you facing?
The cursor.hasNext() has a side-effect:
It is applying the transform, specified in cursor.map(), to the next document in the cursor.
When calling cursor.next() after having called cursor.hasNext(), the transform is applied again against the already transformed document. In my case, this resulted in an error.
I expect the cursor.next() function to apply the transform, but cursor.hasNext() should leave the documents in the cursor as they are.
I expect cursor.hasNext() to just tell me if there is a next document in the cursor, without any side-effects.
What driver and relevant dependency versions are you using?
NodeJS driver 4.12.1
Steps to reproduce?
- create a cursor with a .map function:
const cursor = collection.find({}).map(doc => transform(doc));
- Iterate over cursor:
while(await cursor.hasNext()){ const transformedDoc = await cursor.next(); // this throws an error }
- duplicates
-
NODE-5374 Cursor.hasNext should not transform documents
- Closed