Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

goodeggs/mongoose-querystream-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Execute an async function per document in a streamed query, pausing the stream when a concurrency limit is saturated

Resources

License

Stars

Watchers

Forks

Packages

No packages published