MongoDB: findOne({ _id: id }) returns null for an id string from the URL
@devsingh05▲ 10 net votes
_id is stored as an ObjectId, and a plain string never equals it. Convert: findOne({ _id: new ObjectId(id) }) (from the mongodb package), validating first with ObjectId.isValid(id) to return 404 instead of throwing on bad input. Mongoose casts automatically for findById, but raw driver queries and aggregations do not.