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

Aggregation cursor iteration returns the same document multiple times

    XMLWordPrintable

    Details

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

      Description

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: