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

XMLWordPrintableJSON

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

      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 (Inactive)
            Reporter:
            Jonah Werre
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: