-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.2.7
-
Component/s: MongoDB 3.2
-
Environment:Node Version: 12.4.0 (or 10.14.2)
-
Empty show more show less
Good day folks, the following test for both the cursor.each and cursor.forEach method prints the single aggregation result multiple times:
async function main(db) { const cursor = await this.db.collection('testCollection').aggregate([{"$count": "documentCount"}]); cursor.forEach( (doc) => { console.log('doc:', doc); // document is logged twice }, (err) => { // handle error } ); // OR cursor.each((err, doc) => { if (err) { // handle error } if (doc !== null) { console.log('doc:', doc); // document is logged twice } }); }