w3resource

MongoDB: db.collection.drop() method

db.collection.drop

The db.collection.drop() method is used to removes the specified collection as well as removes any indexes associated with the dropped collection from the database.

Syntax:

db.collection.drop()

db.collection.drop() takes no arguments and will produce an error if called with any arguments.

Example: MongoDB: db.collection.drop() method

Here is the collections in the test database

> show collections
restaurants
restaurants1
system.indexes
user_new
userdetails

The following statement will drop the collection user_new.

db.user_new.drop();

Here is the output.

>db.user_new.drop();
true

Now show the collection list in the test database.

> show collections
restaurants
restaurants1
system.indexes
userdetails

Retrieve the restaurants data from here

Behavior

This method obtains a write lock on the affected database and will block other operations until it has completed.

Previous: db.collection.distinct() method
Next: db.collection.dropIndex() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mongodb/shell-methods/collection/db-collection-drop.php