Not sure of the proper way to pipe query results using MongoDB Node.js Drive 3.0. According to the docs, Cursor::pipe
and AggregateCursor::pipe
receive a Writeable streams so it seems like you should be able to do something like this:
collection.find(query).pipe(process.stdout);
collection.aggregate(query).pipe(process.stdout);
But it turns out to throw an error:
TypeError: Invalid data, chunk must be a string or buffer, not object
This works but it feels a little cumbersome to me doesn't lend itself to pipe chaining.
collection.find(query)
.on('data', function(chunk) {
buffer = Buffer.from(JSON.stringify(chunk))
process.stdout.write( buffer );
});
collection.aggregate(query)
.on('data', function(chunk) {
buffer = Buffer.from(JSON.stringify(chunk))
process.stdout.write( buffer );
});
Is there a way to do a standard pipe chain with with the MongoDB Driver for Node.js?