Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Drop collection


In MongoDB, db.collection.drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections.

The db.collection.drop() method does not take any argument and produce an error when it is called with an argument. This method removes all the indexes associated with the dropped collection.

Syntax:

  1. db.COLLECTION_NAME.drop()

MongoDB Drop collection example

Let’s take an example to drop collection in MongoDB.

First check the already existing collections in your database.

  1. >use mydb
Switched to db mydb 
  1. > show collections
SSSIT
system.indexes

Note: Here we have a collection named SSSIT in our database.

Now drop the collection with the name SSSIT:

  1. >db.SSSIT.drop()
True

Now check the collections in the database:

  1. >show collections
System.indexes

Now, there are no existing collections in your database.

Note: The drop command returns true if it successfully drops a collection. It returns false when there is no existing collection to drop.

Comments

comments