4

I have MongoDB database setup in a Linux server along with a tomcat and everything works great. But i noticed that every 2 or 4 days the whole database collections are dropped. I saw the log of the MongoDB:

Mon Jan 16 08:01:14.375 [PeriodicTask::Runner] task: DBConnectionPool-cleaner took: 11ms
Mon Jan 16 08:01:14.404 [PeriodicTask::Runner] task: WriteBackManager::cleaner took: 12ms
Mon Jan 16 08:01:18.402 [TTLMonitor] query PLEASE_READ.system.indexes query: { expireAfterSeconds: { $exists: true } } ntoreturn:0 ntoskip:0 nscanned:1 keyUpdates:0 locks(micros) r:104348 nreturned:0 reslen:20 104ms
Mon Jan 16 08:25:03.640 [initandlisten] connection accepted from 95.211.153.138:58622 #135 (7 connections now open)
Mon Jan 16 08:25:04.286 [conn135] dropDatabase PLEASE_READ starting
Mon Jan 16 08:25:04.287 [conn135] removeJournalFiles
Mon Jan 16 08:25:04.490 [conn135] dropDatabase PLEASE_READ finished
Mon Jan 16 08:25:04.508 [conn135] command PLEASE_READ.$cmd command: { dropDatabase: 1.0 } ntoreturn:1 keyUpdates:0 locks(micros) W:246737 reslen:62 246ms
Mon Jan 16 08:25:04.579 [conn135] dropDatabase server_db starting
Mon Jan 16 08:25:04.579 [conn135] removeJournalFiles
Mon Jan 16 08:25:04.686 [conn135] dropDatabase server_db finished
Mon Jan 16 08:25:04.686 [conn135] command server_db.$cmd command: { dropDatabase: 1.0 } ntoreturn:1 keyUpdates:0 locks(micros) W:107150 reslen:60 107ms
Mon Jan 16 08:25:04.756 [conn135] dropDatabase local starting
Mon Jan 16 08:25:04.756 [conn135] removeJournalFiles
Mon Jan 16 08:25:04.780 [conn135] dropDatabase local finished
Mon Jan 16 08:25:04.850 [conn135] dropDatabase admin starting
Mon Jan 16 08:25:04.850 [conn135] removeJournalFiles
Mon Jan 16 08:25:04.852 [conn135] dropDatabase admin finished
Mon Jan 16 08:25:04.922 [conn135] dropDatabase test starting
Mon Jan 16 08:25:04.922 [conn135] removeJournalFiles
Mon Jan 16 08:25:04.926 [conn135] dropDatabase test finished
Mon Jan 16 08:25:05.139 [conn135] allocating new ns file /var/lib/mongodb/WARNING.ns, filling with zeroes...
Mon Jan 16 08:25:05.502 [FileAllocator] allocating new datafile /var/lib/mongodb/WARNING.0, filling with zeroes...
Mon Jan 16 08:25:05.537 [FileAllocator] done allocating datafile /var/lib/mongodb/WARNING.0, size: 64MB,  took 0.009 secs
Mon Jan 16 08:25:05.547 [FileAllocator] allocating new datafile /var/lib/mongodb/WARNING.1, filling with zeroes...
Mon Jan 16 08:25:05.567 [conn135] build index WARNING.WARNING { _id: 1 }
Mon Jan 16 08:25:05.569 [FileAllocator] done allocating datafile /var/lib/mongodb/WARNING.1, size: 128MB,  took 0.021 secs
Mon Jan 16 08:25:05.592 [conn135] build index done.  scanned 0 total records. 0.023 secs
Mon Jan 16 08:25:05.653 [conn135] insert WARNING.WARNING ninserted:1 keyUpdates:0 locks(micros) w:492848 513ms

I don't use a TTL index to any of the collections and i don't run any script in Linux to drop the database.

My question is why the collections are dropped? Is it cause of the TTL?

Thank you.

ddarellis
  • 3,912
  • 3
  • 25
  • 53
  • 3
    It looks like you have not secured your MongoDB deployment so remote attackers are able to connect and have full access to your deployment including reading and dropping databases. Please read [How to Avoid a Malicious Attack That Ransoms Your Data](https://www.mongodb.com/blog/post/how-to-avoid-a-malicious-attack-that-ransoms-your-data). – Stennie Jan 17 '17 at 19:56
  • 3
    I would also note that MongoDB 2.4 reached end of life in March, 2016. I strongly recommend upgrading to a currently supported production release (i.e. MongoDB 3.0 or newer as of Jan, 2017). – Stennie Jan 17 '17 at 21:17
  • @Stennie You are write i added a user for the db and added the user credentials to the application.properties file to my spring boot app. No drops anymore! – ddarellis Jan 22 '17 at 19:55

1 Answers1

0

mongodb cannot auto remove collections but it can auto remove BSON records. You just need to set ttl(Time to live) index on a date field that exists in BSON record . You can read more here

https://docs.mongodb.com/manual/tutorial/expire-data/

Shreya Batra
  • 730
  • 1
  • 6
  • 15