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