08 July,2021 by Rambler
Question: We have event log data going into a MongoDB collection. There is no requirement to keep this data beyond 60 days. Is there a way of automating the process to delete the rows , without building procedures to manage the data deleted.
Answer: I'd recommend you use TTL indexes for this type of problem. The TTL (Time to Live) index is based on a single-field .
As part of using a TTL index consider the imapct of rolling this data out of the collection. How critical is the data?
This example creates an index on the "myeventlog" collection - changeDate field. The row will be deleted 1 hr (3600 secs) after the "changeDate"
db.myeventlog.createIndex( { "changeDate": 1 }, { expireAfterSeconds: 3600 } )
Read more on MongoDB
How to read MongoDB system log file
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |