[Online Archive] Custom Criteria with ISODate

Hi, I want to use Atlas Online Archive custom query to remove all items which are older than a specific date as below

{“createdDate”:{"$lt":ISODate(‘2021-01-01’)}}

And because the query must be valid JSON, I cannot use any functions such as ISODate, Date, etc.

Could you please give me some advice on this?

Thank you

Hi Tuan Pham Minh,

Please try your custom archival rule with $expr. Also, we recommend to first check the query execution plan to make sure your query is going to be efficient with the $expr.

Thanks,
Prem

1 Like

Try with extended JSON as specified at

1 Like

You could also experiment with $dataAdd using $$NOW as the starting date.

Something like (untested):

{ "$expr" : {
  "$lt" : [
    "$createdDate" ,
   { "$dateAdd" : {
     "startDate" : "$$NOW" ,
     "unit": "year" ,
     "amount" : -1 } }
  ]
}}
1 Like