我在Linux服务器上安装了MongoDB数据库以及一个tomcat,一切都很好。但我注意到每隔2或4天就删除整个数据库集合。我看到了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
我没有对任何集合使用TTL index,并且我没有在Linux中运行任何脚本来删除数据库。
我的问题是收藏品被删除的原因?它是TTL的原因吗?
谢谢。
答案 0 :(得分:0)
mongodb无法自动删除集合,但可以自动删除BSON记录。您只需要在BSON记录中存在的日期字段上设置ttl(生存时间)索引。你可以在这里阅读更多内容