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

countDocuments throws error when query matches zero docs

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 3.1.1
    • Affects Version/s: 3.1.0
    • Component/s: None

      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.
       

            Assignee:
            rebecca.weinberger Rebecca Weinberger
            Reporter:
            alex.stanciu@auth0.com Alex Stanciu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: