Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

What is the best way to drop a collection in MongoDB?

I am using the following:

db.collection.drop()

As described in the manual:

db.collection.drop()

Removes a collection from the database. The method also removes any indexes associated with the dropped collection. The method provides a wrapper around the drop command.

But how can I drop it from the command line?

2 Answers

0 votes
by (106k points)

You can use the below-mentioned code to drop a collection in MongoDB:-

mongo <dbname> --eval 'db.<collection>.drop()' db.<collection>.drop()

0 votes
by (108k points)

To drop a collection named 'doc1' of database 'database1':

$ use database1

$ db.doc1.drop()

Related questions

0 votes
2 answers
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 7, 2020 in Web Technology by ashely (50.2k points)

Browse Categories

...