-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Component/s: None
-
None
When using the $sample operator with the aggregate command on 3.2.1 the command will sometimes return a first result with the following structure regardless of the batchSize passed to the aggregate command.
{ waitedMS: 0,
cursor:
{ id: 15827158826,
ns: 'integration_tests.bigdocs_aggregate_sample_issue',
firstBatch: [] },
ok: 1 }
No initial results but a live cursor. Drivers must ensure they do not treat this as an empty cursor but correctly exhaust the cursor issuing getMore commands. Below is the node.js test case used to reproduce the issue with 3.2.1
var co = require('co'); co(function*() { var db = configure.newDbInstance({w:1}, {poolSize:1}); db = yield db.open(); var string = new Array(6000000).join('x'); // var string = new Array(600000).join('x'); // Get the collection var collection = db.collection('bigdocs_aggregate_sample_issue'); // Go over the number of for(var i = 0; i < 100; i++) { var r = yield collection.insertOne({ s: string }); } // count just to make sure we're getting something back var count = yield collection.count(); console.log('counting %d docs.', count); var options = { maxTimeMS: 10000, allowDiskUse: true }; var index = 0; collection.aggregate([{ $sample: { size: 100 } }], options) .batchSize(10) .on('error', function(err) { console.error('error: ', err); db.close(); process.exit(1); }) .on('data', function(data) { console.log('data received :: ' + (index++)); }) // `end` sometimes emits before any `data` events have been emitted, // depending on document size. .on('end', function() { console.log('end received'); db.close(); test.done(); }); });
- depends on
-
CDRIVER-1159 Add test to show aggregation results can be iterated even if first batch is empty
-
- Closed
-