mongoose-querystream-worker
v3.0.1
Published
Execute an async function per document in a streamed query, pausing the stream when a concurrency limit is saturated
Downloads
32
Readme
mongoose-querystream-worker
Execute an async function per document in a streamed query, pausing the stream when a concurrency limit is saturated. Think async.queue but for Mongoose QueryStreams. Built on top of stream-worker.
require('mongoose-querystream-worker');
/* Promises: */
Model.find().stream().concurrency(n).work(function (doc) {
/* ... work with the doc ... */
return doc.save(); /* returns a promise */
})
.then(function() {
/* ... all workers have finished ... */
}, function(err) {
/* ... something went wrong ... */
});
/* Callbacks: */
Model.find().stream().concurrency(n).work(
function (doc, done) {
/* ... work with the doc ... */
},
function (err) {
/* ... all workers have finished ... */
}
);