-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.5.2
-
Component/s: None
-
Empty show more show less
Hi there, first of all, thanks for your amazing work : )
We recently upgraded our application to use the 3.5.2 mongo driver and we experience some problems when piping our cursor into writable streams.
Here is a minimal example of reproduction
package.json
{ "dependencies": { "mongodb": "3.5.2" } }
index.js
const MongoClient = require('mongodb').MongoClient; const Transform = require('stream').Transform; const url = 'mongodb://localhost:27017'; const client = new MongoClient(url, { useUnifiedTopology: true }); (async () => { await client.connect(); const db = client.db('testDb'); const collection = db.collection('documents'); await collection.drop(); await collection.insertMany([ { a: 1 }, { a: 2 }, { a: 3 } ]); const cursor = collection.find({}, { sort: { a:1}}); cursor.hasNext(); // <= here cursor.pipe(new Transform({ objectMode:true, transform: (chunk, encoding, next) => { next(null, JSON.stringify(chunk)); } })) .pipe(process.stdout); })();
Version of node.js
v10.15.0
the output is :
{"_id":"5e442683c11e6609f16af231","a":2}{"_id":"5e442683c11e6609f16af232","a":3}
If i remove the cursor.hasNext();
the output is
{"_id":"5e4426b7d3c8f60d33560256","a":1}{"_id":"5e4426b7d3c8f60d33560257","a":2}{"_id":"5e4426b7d3c8f60d33560258","a":3}
Thanks for your help, tell me if you need any other information
- is cloned by
-
NODE-2486 Each Cursor.hasNext() call seems to consume an entry when used with a request limit
- Closed