MongoDB Drop Collection

MongoDB Drop Collection

 MongoDB Drop Collection


Use db.collection.drop() statement to delete existing collection. The result will be true on successful deletion.

Syntax

> db.COLLECTION_NAME.drop()

First, use the below commands to select the database and list available collections.

> use mydb
> show collections

tecadmin
accounts
mycol

MongoDB Drop Collection

Finally, delete the collection named admin using the below methods from the mydb database.

> db.tecadmin.drop();

true

Also, you can also use drop() method with getCollection() to remove the existing collection as follows.

> db.getCollection("tecadmin").drop();

true
Reactions

Post a Comment

0 Comments

close