MongoDB Drop Collection

The MongoDB drop Collection statement is used to drop an exiting collection. It does not require specifying the collection name, because by default the command removes the currently selected collection.So, first connect to the database in which you want to delete collection and then type the following command to delete the collection:

Note:We use the remove() function, so that only the documents in the collection are removed, but do not remove the collection itself and the indexes created on it.

Drop Collection Syntax :

The syntax of the Drop Collection is −

 
\\Syntax of Drop collection
db.collection_name.drop()


Drop Collection Example :

The Example of the Drop Collection is −

\\Example of Drop the Collection in MongoDB
> use mydb
switched to db mydb
> show collections
mydbs
trainee
professor
> db.professor.drop()
true
> show collections
mydbs
trainee 






Visit :


Discussion



* You must be logged in to add comment.