mongo-each
Queued asynchronous iterating over mongodb cursor without duplicates
API
each(cursor, iterator, [options], callback)
cursor
- a mongodb cursoriterator
-function(doc, cb)
- iterator functionoptions
- optionalconcurrency
- how manyiterator
functions should be run in parallel (default:100
)batch
- batch mode (default:false
)batchSize
- batch size (default:10
)
callback
-function(err)
callback which is called when all iterator functions have finished, or an error occurs
Example
var MongoClient = require('mongodb').MongoClient,
each = require('mongo-each');
MongoClient.connect('mongodb://127.0.0.1:27017/data', function(err, db) {
if(err) throw err;
var collection = db.collection('data'),
cursor = collection.find();
each(cursor, function(doc, callback) {
process.nextTick(function() {
console.log(doc);
callback();
});
}, {
concurrency: 50
}, function(err) {
console.log('err: ', err);
console.log('completed');
});
});
License
MIT