-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 6.8.0
-
Component/s: None
Use Case
Recently upgraded to the MongoDB driver version 6.8.0. We were running on 6.7.0 before.
Documents are versioned and have an _id of the structure.
_id: { id: ObjectId; version: number }
We were consuming a cursor using the following pattern in a JavaScript generator.
We always return the first matching document and then iterate until a certain condition is met.
const documentId = ...some ObjectId; const cursor = collection.find({ '_id.id': documentId }, { sort: { '_id.version': -1 } }); const document = await cursor.next(); yield document; for await (const document of cursor) { ... yield document; // break out of loop depending on a condition }
Suppose I have 2 documents matching the filter. The cursor.next() call returns one of them, but since version 6.8.0 it never goes inside of the loop again. Downgrading to 6.7.0 worked fine.
Is this because cursor responses are now parsed lazily?
https://github.com/mongodb/node-mongodb-native/releases/tag/v6.8.0
User Experience
- I would expect looping through my cursor to return all the documents matchign the filter.
- related to
-
NODE-6255 Calling `next()` on a closed cursor no longer throws an error
- Ready for Work