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

Error using aggregate and cursor events

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: 3.2.3
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      node 10.15.0
      mongodb nodejs driver 3.2.3
      MongoDB 3.4.20
    • MongoDB Version:
      3.4.20

      Description

      Hi there,

      I have an error "Cannot read property 'high_' of null" when using aggregate and setting event listeners on the cursor. Here is the code to reproduce the issue:
      const MongoClient = require('mongodb').MongoClient;
      const assert = require('assert');

      // Connection URL
      const url = 'mongodb://localhost:27017';

      // Database Name
      const dbName = 'test';
      const client = new MongoClient(url);

      // Use connect method to connect to the server
      client.connect((err) => {
      assert.equal(null, err);
      console.log('Connected successfully to server');

      const db = client.db(dbName);

      const col = db.collection('test');

      col.updateOne(
      {
      _id: '1',
      },
      { $set: { duration: 10 } },
      { upsert: true },
      )
      .then(() => {
      col.aggregate([
      {
      $group: {
      _id: null,
      totalDuration: { $sum: '$duration' },
      },
      },
      ], (err, cursor) => {

      // remove this listener and the exception does not throw
      cursor.on('data', () => console.log('cursor data'));

      cursor.toArray((err, documents) => {
      console.log(documents);
      });
      });
      });
      {color:#d4d4d4}});
       
       
       

        Attachments

          Activity

            People

            Assignee:
            daniel.aprahamian Daniel Aprahamian (Inactive)
            Reporter:
            michaelbailly Michael Bailly
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: