Execute an async function per document in a streamed query, pausing the stream when a concurrency limit is saturated
JavaScript Makefile
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
Makefile
README.md
mongoose-querystream-worker.js
package.json

README.md

mongoose-querystream-worker build status

DEPRECATED - In light of Mongoose QueryStreams being deprecated in favor of Mongoose QueryCursors, may as well just depend on stream-worker directly, rather than maintaining this lightweight syntatic layer.

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 */
}, {promises: true})
.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 ... */
  }
);