Thursday, 3 August 2023

Drop Database Drop Collection

 Drop collection from database in mongoDB

db.collection.drop() is used to drop a collection from the database.

Syntax: db.collection.drop()

use TEST

show collections     <——— check the available collections into your database TEST.

db.student.drop()    <——– Check and verify the student collection has been drop from TEST Database.

 

Drop Database in mongoDB

db.dropDatabase() command is used to drop a existing database.

Syntax: db.dropDatabase()

Example:

show dbs     <—– check the database list and select you want to drop.

use TEST      <—– Put the db in usable state.

db.dropDatabase()    <—— Now the Test database has been drop check & verify with show dbs command.

No comments: