0 votes
1 view
in Web Technology by (47.8k 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 (107k 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 (78.1k 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
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...