Is it possible to expire data in MongoDB based on multiple properties? -
I'm trying to clean my MongoDB and I thought about it. . But I need separate TTLs for my documents based on a second asset,
Here's an example:
{"_ id": ObjectId ("525bd2aee4b05e96f1ec7362 "525bd2aee4b05e96f1ec7361", "serviceId": "525bd2ade4b05e96f1ec735f", "Status": "Start", "Timestamp": ISODate ("2013-10-14T11: 17: 01.651Z"), "Transaction" "525bd2aee4b05e96f1ec7360"} I can set up a TTL on the property timestamp , but I have a different based on serviceId TTL is required. This MongoDB 2.2.x ? After
No, it is possible in a TTL index that there is no conditional argument in which the field & Lt; Now - expireAfterSeconds then delete the document However, there is a solution that can work in your situation: You have a specific date in the future where you want to expire your document. So, you You can add a field expireDate , which you can set in the future on the date where you want to end the document when you create the index from expireAfterSeconds to 0 , Then each document will be deleted when its expiredDate passes. This trick allows you to keep documents with different TTLs in the same collection.
Comments
Post a Comment