How to drop a database with Mongoose?

There is no method for dropping a collection from mongoose, the best you can do is remove the content of one : But there is a way to access the mongodb native javascript driver, which can be used for this Warning Make a backup before trying this in case anything goes wrong!

Mongoose.js: remove collection or DB

Yes, although you do it via the native MongoDB driver and not Mongoose itself. Assuming a required, connected, mongoose variable, the native Db object is accessible via mongoose.connection.db, and that object provides dropCollection and dropDatabase methods.

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