2 Sept 2023

Deleting a Collection in MongoDB

To drop a collection in MongoDB, you can use the drop() method on the collection object. Here is an example of how to drop a collection named 'users':

db.users.drop()

Here, db is the name of the current database, and users is the name of the collection you want to drop. The drop() method is a MongoDB command that is used to delete a collection.

You can also use the following command to drop a collection in MongoDB

db.runCommand( { drop: "users" } )

This command uses the runCommand() method and pass a JSON object containing the drop key with the value of the collection name.