Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

mongoose-querystream-worker

3.0.1 • Public • Published

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

Install

npm i mongoose-querystream-worker

DownloadsWeekly Downloads

155

Version

3.0.1

License

MIT

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar