Sometimes, we want to drop a database with Mongoose.
In this article, we’ll look at how to drop a database with Mongoose.
How to drop a database with Mongoose?
To drop a database with Mongoose, we can remove all the content of a collection.
For instance, we write
Model.remove({}, (err) => {
console.log('collection removed')
});
to call Model.remove
with an empty object to remove all items in the collection that’s mapped to Model
.
The callback is run when all the items are removed from the collection.
Conclusion
To drop a database with Mongoose, we can remove all the content of a collection.