3.0.1 • Published 8 years ago

mongoose-querystream-worker v3.0.1

Weekly downloads
864
License
MIT
Repository
github
Last release
8 years ago

mongoose-querystream-worker build status

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 ... */
  }
);