Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1408

How to pipe with MongoDB Node.js Driver Cursor and AggregateCursor?

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.6
    • Affects Version/s: 3.0.6
    • Component/s: Native
    • Labels:
    • Environment:
      MongoDb v3.4.13, Node.js v6.13.0, Node.js MongoDB Driver 3.0.6

      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?

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            jonah@surveyplanet.com Jonah Werre
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: