Hi guys I am a beginner in learning mongodb ,I had dropped my database using dropDatabase( ) and after I had checked the db list it is not there in it.But when I tried to create a new database with droped db name it showing that it is alreedy exist.why?


Hi @Sujith_Basham

That is normal in mongosh. The database was dropped, but your database context still exists. The moment you create an object in the database it will be actually created.

If you change db to admin and list the databases you will see that students does not exist. Or you can use the listDatabases command to the same effect. Example of both below:

mongosh 'mongodb://'  --quiet
students> db.dropDatabase()
{ ok: 1, dropped: 'students' }
students> db.adminCommand({listDatabases:1}).databases.forEach(x => print(x.name))

students> use admin
switched to db admin
admin> show dbs
admin   40.00 KiB
config  48.00 KiB
local   72.00 KiB
test    72.00 KiB