2017-01-23 70 views
1

我使用Robo Mongo來運行我的MongoDB查詢。我有一個包含日期時間的'requestReceivedTimestamp'列的集合(例如:2016年12月13日23點18分56秒)。我已經使用下面的命令來設置此列上的TTL Expiry索引。出於某種原因,我沒有看到記錄被刪除。我在這裏做錯了什麼?設置TTL不會刪除MongoDB中的記錄

db.logging.createIndex({ "requestReceivedTimestamp": 1 }, { expireAfterSeconds: 2592000 }) - >運行此命令在'requestReceivedTimestamp'

創建TTL索引,以使MongoDB的TTL監測:db.adminCommand({setParameter:1, ttlMonitorEnabled:true}); - >此命令,以確保ttlMonitor爲ON。我不知道該怎麼看,如果是ONOFF,所以我運行這個命令來打開它。

這就是使用mongo DB的數據外觀。

How the collection looks like in RoboMongo

回答

0

感謝保羅·雷伊。在使用新的Date()插入列數據後,我能夠在用ttl過期日期對新列編制索引後刪除行。使用相同的命令 - db.logging.createIndex({ "recordCreateDate": 1 }, { expireAfterSeconds: 2592000 })

Image of the inserted record

+0

不客氣,我很高興能幫助你:) –