Database delete automatic

Hi .
I have issues with creating a new database , everytime i create a database its deleted and i dont know what is the problem.

I could use some help please.

Hello @avishay_avraham, and welcome to the MongoDB Community forums! :wave:

This is not normal. MongoDB will not automatically delete a database without command like db.runCommand( { dropDatabse: 1 } ) or db.dropDatabase() being run.

Can you explain the process where you see this happening?

Welcome to the MongoDB Community @avishay_avraham !

As @Doug_Duncan mentioned, databases do not delete themselves automatically.

If you can provide more details we should be able to help you work out what is happening:

  • version of MongoDB server?

  • is this server exposed to the internet?

  • do you have password authentication and access control enabled? (see MongoDB Security Checklist)

  • how are you creating the new database and what is the tool or driver version used?

  • how are you confirming the database has been deleted and what is the tool or driver version used?

A few likely things to check:

  • are you connecting to the same deployment and database

  • are you using compatible tool/driver versions to connect to your deployment to read the data

  • is your deployment open to remote connections and accidentally unsecured

Regards,
Stennie

One other thing I just thought of is that if all the collections in the database are dropped, then the database itself is removed from the system. Are you by chance dropping collections?

Database is automatically created when you issue

use database

I am not too sure about

mongosh> show dbs
data            73.7 kB
equipoule       21.7 MB
forums            41 kB
nota_bene_test   115 kB
poem              41 kB
prototype        582 kB
salon           22.7 MB
test             213 kB
zoo              111 kB
admin            348 kB
local           3.13 GB
mongosh> use Tin_Cvitkovic
'switched to db Tin_Cvitkovic'
mongosh> show dbs
data            73.7 kB
equipoule       21.7 MB
forums            41 kB
nota_bene_test   115 kB
poem              41 kB
prototype        582 kB
salon           22.7 MB
test             213 kB
zoo              111 kB
admin            348 kB
local           3.13 GB

However it does get created if you insert into a collection.

mongosh> db.test.insertOne( { _id : 1})
{ acknowledged: true, insertedId: 1 }
mongosh> show dbs
Tin_Cvitkovic   8.19 kB
data            73.7 kB
equipoule       21.7 MB
forums            41 kB
nota_bene_test   115 kB
poem              41 kB
prototype        582 kB
salon           22.7 MB
test             213 kB
zoo              111 kB
admin            348 kB
local           3.13 GB
2 Likes

That’s what I meant, you dont need a special “CREATE DATABASE” command, maybe he justed switched but didn’t insert anything hence thinking that newly created database has been removed. Thats was my 0.02 $ :slightly_smiling_face:

2 Likes