MongoDB database deleted automatically
Asked Answered
F

3

8

I am very confused with the MongoDB behavior I am facing these days. I am running a MEAN(MongoDB, Express, Angular, NodeJS) application on a windows live server. Two times it happened that the whole database my application is connected with is deleted automatically. I have no clue what is happening with it. I have searched the web but found no answer on it. I am using Monk for the MongoDB.

How can I detect the problem with it?

Forthwith answered 11/1, 2017 at 9:39 Comment(0)
S
21

Hey It is a virus attack read this article https://www.bleepingcomputer.com/news/security/mongodb-apocalypse-professional-ransomware-group-gets-involved-infections-reach-28k-servers/

Actually more than 28k mongodb server have been attacked by the community and they have either deleted the database or have encrypted them. Now they are demanding Bit coin for giving backup.

Now the Question arises that is mongoDb safe as so many database have been deleted or encrypted

Answer is YES Mongodb is completely safe the reason behind this was the lack of security measures used by the programmers.

  1. You should only open the port of the server that are required example in Amazone web server (AWS) some programmers Open all the ports of security groups stop doing that.

Now come to the solution of the problem.

Do check mongod.conf file on the server:

When we install mongodb a file name mongod.conf is automatically generated on the server. you can check it by following command.

cd /etc/
sudo vim mongod.conf

in this image you will find bindIp is 127.0.0.1 which is a localhost means only this server is allowed to use the database in your case this must be 0.0.0.0 which allow the hackers to get access to your data and delete all the files so just update the bindIp to 127.0.0.1 and it wont happen as of now.

Even you can use mongo Authentication use this link for further reference https://docs.mongodb.com/manual/tutorial/enable-authentication/

enter image description here

Sierra answered 11/1, 2017 at 10:16 Comment(1)
This is happening to me too and the bindIp is already set to 127.0.0.1. Any idea?Busk
P
1

I have noticed a behavior:

Create new Database > do not add ANY data (collections / documents) yet > disconnect your mongodb client > re-connect to mongodb > boom, the new database disappears!

And when there is some data added, it obviously doesn't auto remove the database.

I guess this is default behavior of mongodb, or may be the client i use (Robo 3T).

Participate answered 10/1, 2020 at 7:7 Comment(1)
Databases and collections are created only when documents are first inserted. This behavior is consistent with MongoDB’s dynamic approach to data; just as the structure of documents needn’t be defined in advance, individual collections and databases can be created at runtime. This can lead to a simplified and accelerated development process.Manns
Y
0

I had this same problem. Every time bot started, it had code to create a DB if there wasn't one found in the main coding, and a command to create a db manually.

Turns out I had copied the wrong code from "Find one and update" to "Find one and delete" lmao. So every time the bot started with the db, it'd run through that code, delete the db and I'd be left puzzled.

tl;dr check your coding carefully. Follow the arrows and // code until you find the one that changes your DB.

Yanez answered 7/9, 2022 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.