Drop Collection in MongoDB

For dropping a collection in MongoDB, you have to make use of the collection.drop() method. This will eliminate the collection from the database completely and will not leave any indexes that are connected to this drop collection. It is also to be noted that, this collection dropping method has no argument in it and will pop up with errors in case arguments are passed. All the indexes associated with the collection gets dropped once this method is executed.

The syntax for using this method is:

Syntax:
db.collection_name.drop()

Here is an example that is showing the use of the drop() method:

Continuing from the example in the previous lesson where you have created a collection inside the my_project_db database. Now use this database to remove or drop the movie collection and see the changes:

Example:
use my_project_db
db.movie.drop()
show collections
Output:


Scroll Back to Top