[DRIVERS-289] Aggregation command cursor corner case using $sample operator Created: 01/Mar/16  Updated: 15/Apr/19  Resolved: 12/Apr/17

Status: Closed
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Christian Amor Kvalheim Assignee: Barrie Segal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CDRIVER-1159 Add test to show aggregation results ... Closed
Driver Compliance:
Key Status/Resolution FixVersion
CDRIVER-1159 Done 1.4.0

 Description   

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();
    });
});



 Comments   
Comment by Githook User [ 17/Mar/16 ]

Author:

{u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}

Message: DRIVERS-289: Test iteration on live command cursor with empty first batch
Branch: master
https://github.com/mongodb/mongo-php-driver/commit/6915ffd37f31cb3a3d405812b96f506ae726762b

Generated at Thu Feb 08 08:21:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.