Mongoose: CastError: Cast to ObjectId failed for value “[object Object]” at path “_id”

Short answer: use mongoose.Types.ObjectId. Mongoose (but not mongo) can accept object Ids as strings and “cast” them properly for you, so just use: However, the caveat is if req.params.id is not a valid format for a mongo ID string, that will throw an exception which you must catch. So the main confusing thing to understand is that mongoose.SchemaTypes has stuff … Read more

Difference between MongoDB and Mongoose

I assume you already know that MongoDB is a NoSQL database system which stores data in the form of BSON documents. Your question, however is about the packages for Node.js. In terms of Node.js, mongodb is the native driver for interacting with a mongodb instance and mongoose is an Object modeling tool for MongoDB. mongoose is built on top of the mongodb driver to provide programmers … Read more