0

I am new to MongoDB, I am trying to insert my db object using the below code, i am able to insert successfully but the DBobject is not removing after the given time it is still in db. Can any one give me example to insert the Dbobject correctly.

 BasicDBObject ttlIndexObj = new BasicDBObject("actionDate", 1);
 BasicDBObject ttlIndexObjOption = new BasicDBObject("name", 
 "actionDate_ttl_7_days").append("expireAfterSeconds", 204800);
  collection.createIndex(ttlIndexObj, ttlIndexObjOption);
jcoder
  • 23
  • 7

1 Answers1

0

Do read the documentation here. For TTL to work the indexed field has to be a Date.

And also the documents deleted may no be exactly after the times you specified. It may vary because the background task that removes expired documents runs every 60 seconds.

pvpkiran
  • 25,582
  • 8
  • 87
  • 134