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?

image

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://127.6.0.1/students'  --quiet
students> db.dropDatabase()
{ ok: 1, dropped: 'students' }
students> db.adminCommand({listDatabases:1}).databases.forEach(x => print(x.name))
admin
config
local
test

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
3 Likes