I was working on some interesting feature of MongoDB know as TTL (Time to live) after understanding and google about the feature. I found that it's a very easy and use full feature of MongoDB for those who don't want to keep the unnecessary data/collection/documents in there MongoDB collection/table, so more like TTL is act like a background Job which executed on specific number of second. It's working based on index's in MongoDB for deleting the record/collection.
For detail understanding please visit: official documentation.
In my case : I need this to be work after every month for every single record so I added date but it's not working and because once on any collection you create a TTL index then I will not update the TTL expiration date value. So it's a bad way to do this also I notice that the TTL field are not Date type so if you are using : expireAfterSeconds then please try to use number which is Seconds.
db.log_events.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } )
No comments:
Post a Comment