# When the Database Says No: Bad ids, Duplicates and Not Found

An API answers each way a request can fail with the status that says whose problem it is, so a text that isn't an ObjectId gets 400, an id with no pet 404, a duplicate key (code 11000) 409, a document the validator refuses (code 121) 400, and a database that's down 500 with the details logged and never sent.

![Cheat sheet: When the Database Says No: Bad ids, Duplicates and Not Found](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/d65e4abed2ee4b618aa9c676b4e38973.webp)

- Category: MongoDB
- Level: Journeyman
- Tags: 400 Bad Request, 404 Not Found, 409 Conflict, 500 Internal Server Error, Duplicate Key Error, Error-Handling Middleware, mongodb, nodejs
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/mongodb-driver-when-the-database-says-no-cheat-sheet
