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

Cursor.forEach should handle async callback

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: next
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      Ubuntu Linux 18.04 latest
    • MongoDB Version:
      4.0.12

      Description

      Right now if you specify an async function as the callback for a Cursor.forEach, not all off the callbacks will execute, since forEach doesn't recognize that the callback returned a Promise.

      Use case:

       

      Doing a Cursor.forEach on a parent collection, but inside the callback you want to do a child.findOne() to do some additional things. The findOne is async....but if you do an await on the findOne, it means you have to tag the forEach callback as async and then later callbacks are not guaranteed to ever complete.

      It would be great if forEach detected if a callback returned a Promise and if so, waited for that Promise to complete before iterating to the next document in the Cursor.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            ataramina@shorecg.com Andrzej Taramina
            Participants:
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: