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

Error using aggregate and cursor events

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.3
    • Component/s: Core
    • Environment:
      node 10.15.0
      mongodb nodejs driver 3.2.3
      MongoDB 3.4.20

      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}});
       
       
       

        1. repro.js
          1.0 kB
          Michael Bailly

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

              Created:
              Updated:
              Resolved: