cursor-stream

1.2.0 • Public • Published

Cursor Stream

NPM version build status Test coverage Gittip

A streams2 wrap around MongoDB cursors because it current uses Streams1 like it's 2010.

API

var wrap = require('cursor-stream');
 
var cursor = db.things.find();
var stream = wrap(cursor);
 
stream.on('data', function (doc) {
  console.log(doc)
})

var stream = wrap(cursor, [options])

Wraps a cursor and returns a Stream.Readable.

Options:

  • transform - optional transformation to apply to each doc. For example, to stringify all the documents, you can do transform: JSON.stringify.

stream.toArray([callback]).then()

Return all the results of the cursor as an array. Similar to cursor.toArray(), except it returns a Promise if no callback is passed.

stream.toArray().then(function (arr) {
  console.log(arr)
})
 
stream.toArray(function (err, arr) {
  if (err) return console.error(err.stack)
 
  console.log(arr)
})

Readme

Keywords

none

Package Sidebar

Install

npm i cursor-stream

Weekly Downloads

3

Version

1.2.0

License

MIT

Last publish

Collaborators

  • jongleberry