-
Type: Bug
-
Resolution: Gone away
-
Priority: 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
-
Empty show more show less
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}});