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

Package Sidebar

Install

npm i mongoose-querystream-worker

Weekly Downloads

1

Version

3.0.1

License

MIT

Last publish

Collaborators

  • goodeggs-admin
  • randypuro
  • sylspren
  • hurrymaplelad
  • bobzoller