1.2.0 • Published 10 years ago

cursor-stream v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

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)
})
1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago