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

Aggregation cursor iteration returns the same document multiple times

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.7
    • Component/s: MongoDB 3.2
    • Labels:
    • Environment:
      Node Version: 12.4.0 (or 10.14.2)

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

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

              Created:
              Updated:
              Resolved: