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

countDocuments throws error when query matches zero docs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 3.1.0
    • Fix Version/s: 3.1.1
    • Component/s: None
    • Labels:
      None

      Description

      This line:

      https://github.com/mongodb/node-mongodb-native/blob/3.1/lib/operations/collection_ops.js#L237

      will throw an error if the query to countDocuments does not match:

      db.collection('somecollection').countDocuments({foo: 'blah'})
      

      Uncaught TypeError: Cannot read property 'n' of undefined

      `docs` is an empty array if the query does not match.
       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: