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
Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close