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

Add option to throw error when no results are found



    • New Feature
    • Status: Closed
    • Unknown
    • Resolution: Works as Designed
    • None
    • None
    • None
    • 1
    • Not Needed


      How are you using Mongo? What version of the server and driver are you using? Node.js v18.5.0 running MongoDB v4.7.0

      What is the feature/improvement you would like?

      I'd like to see an option added to the client constructor that would let us choose whether we want the application to throw an error when making a call to the DB and not finding any results. This would work on findOne, updateOne and deleteOne, as well as find, updateMany and deleteMany. There would also be an option on each one of these requests that would override the client option when provided so we can choose to throw an error on specific requests but not all, or vice-versa. For bulkWrite requests, it could throw if at least one of the requests fails.

      What use case would this feature/improvement enable? 

      This would be useful for situations where your code absolutely needs to find that DB element and would help us identify issues when it can't. It would also help to remove `|null` from findOne typings as we'd be sure the request either succeeds or fails, never returns null.


        Issue Links



              durran.jordan@mongodb.com Durran Jordan
              rodrigoleitao25@gmail.com Rodrigo Leitão
              Durran Jordan
              0 Vote for this issue
              3 Start watching this issue