mongodb drop collection
To drop a collection in MongoDB, you can use the drop()
method. Here are the steps to drop a collection in MongoDB:
Open the MongoDB shell: Open a terminal or command prompt and run the
mongo
command to open the MongoDB shell.Switch to the database containing the collection you want to drop: Use the
use
command followed by the name of the database to switch to the database containing the collection you want to drop. For example, to switch to a database named "mydb", run the following command:
use mydbSource:www.theitroad.com
- Drop the collection: Run the
drop()
method on the collection you want to drop. For example, to drop a collection named "mycollection", run the following command:
db.mycollection.drop()
- Confirm the collection has been dropped: MongoDB will return a message indicating that the collection has been dropped. You can also check for the existence of the collection by running the
show collections
command.
Note that dropping a collection will permanently delete all data stored in that collection. Make sure to back up any important data before dropping a collection.