cursor-stream
v1.2.0
Published
wrap a MongoDB cursor in a streams2
Downloads
9
Readme
Cursor Stream
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 dotransform: 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)
})