-
Type: Bug
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: 6.8.0
-
Component/s: Mongoose
Use Case
As a... developer
I want... to get an error message when I try to use a closed cursor
So that... this is the behavior in 6.7.0
User Impact
Mongoose tests fail when using Node driver 6.8.0. This blocks Mongoose from using Node driver 6.8.0.
The test that failed is called gh-4258 which was closed by 4a4662a and the test was added in ecf8ed1 (link to modern version)
Dependencies
N/A
Unknowns
- What is the expectation for a cursor that is closed but still has documents to return versus one that has exhausted in its first batch?
- What about tail-able cursors that do not exhaust?
Acceptance Criteria
- The driver should always throw a CursorExhaustedError if the cursor is closed while it has not been exhausted. This matches pre-6.8.0 behavior.
- The following script should succeed (add a test that adapts this logic to driver test suite code)
const mongodb = require('mongodb'); const assert = require('assert'); async function run() { const client = new mongodb.MongoClient('mongodb://localhost:27017'); try { await client.connect(); const db = client.db('testdb'); const collection = db.collection('testcollection'); // Inserting a document to ensure the test case runs properly await collection.insertMany([{ name: 'Axl', test: 'test' }]); const cursor = collection.find().sort({ name: 1 }); const doc = await cursor.next(); assert.equal(doc.name, 'Axl'); assert.equal(doc.test, 'test'); await cursor.close(); try { await cursor.next(); assert.ok(false); } catch (error) { console.log('B', error); assert.equal(error.name, 'MongoCursorExhaustedError'); } } catch (err) { console.error(err); } finally { await client.close(); } } run().catch(console.dir);
Implementation Requirements
- Determine when it is expected for Exhaustion errors to throw.
- The driver should always throw a CursorExhaustedError if the cursor is closed while it has not been exhausted.
- Correct regression
Testing Requirements
- See mongoose test and reproduction script.
Documentation Requirements
- Add API docs that clarify when an Exhaust error throws from a cursor API
Follow Up Requirements
- Let mongoose developers know what version this fix is available in
- is related to
-
NODE-6367 Change in cursor behavior, not all documents are returned
- Closed