For live applications, we don’t have an option to drop a collection or database by using interface. In most cases, we need to provide the deployment teams with a script to execute. The below-mentioned script can be used to drop a MongoDB database from the command line.
mongo <yourdbname> --eval "db.dropDatabase()"
Check out this link for more references.
Here “yourdbname” is the name of the database that you want to drop.
This command is also useful in dropping databases that have special characters in the name which are not allowed to be dropped from the command line.
What is a drop database in MongoDB?
“Drop” database Removes the current database, deleting the associated data files. It will remove the database from your Mongo instances.
Why do we need to Drop the MongoDB database?
At times we are in a position where we are running out of disk space on our Mongo server. We find that there are many backup databases instances that we created in case some deployment changes break the release. Using a drop database for these backup instances can help us recover some disk space.
Why do we need to Drop the MongoDB database from the command line?
Most of the time the development teams don’t have access to production servers and it’s the deployment team that takes care of running the provided scripts. This could be solved by providing a script to drop the MongoDB database which can be run from command line.
Hope the above solution will help you in clearing some disk space.
Happy Coding 🙂
- Best practices for unsubscribing from subscriptions of Observables in Angular
- 10 best practices for creating Angular Application
- How to GroupBy in MongoDB
- How to Join two collections in MongoDB
- How to take screenshot on Android Phone- Samsung, Redmi Note