Aggregation cursor iteration returns the same document multiple times

XMLWordPrintableJSON

    • 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)
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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 (Inactive)
              Reporter:
              Steven Chin
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: