Hi,
I have to automatically delete/expire documents based on two conditions:
-they have field1= “A”
-they have the date_field_b greater that 6 months with respect to current date
I found out TTL Partial Index documentation but I have some issues to implement this.
Can anyone help me?
I’ve got some documents structured as follows:
id: A1234
publishDate: 2023-12-21T17:00:50.348+00:00
flag : Done
I would like to automatically delete all documents where flag=Done and publishDate=publishDate+6months.
I found out some documentation on TTL Index, but I do not know where to start
You would need to replace 3600 to what ever value correspond to 6 months, which could be tricky because not every months have the same number of seconds.
I’ve tried and it gave me an error: “MongoServerError: Invalid field specified for createIndexes command: commitQuorum”. I’ve got MongoDB version 1.39 : does it not support the ttl partial index?
How did you get the version? I do not know the version history of TTL index, but you might not be able to implement your use-case directly. But before jumping to conclusion, please share the exact command that you tried.
The following worked for me.
It looks like the syntax from the example I got from the link I provided is wrong. What I understand is that both optionspartialFilterExpressionandexpireAfterSecondshave to be inside the same parameter object.
Dear @Olimpia_Andreea_Brendea, I spent some of my free time to work on your issue, I would appreciate a followup and perhaps closure by marking one of my post as the solution.