locked
how to create a scheduled job that purges old data? RRS feed

  • Question

  • Hi,

    I want to have something run periodically to purge old data given some query conditions. I found the TTL feature could be handy if the purge doesn't require any condition. But given search conditions, is there a way to setup a scheduled job that runs a stored procedure to find and purge old data from documentDB?

    Thanks,


    Fan

    Thursday, July 14, 2016 12:38 AM

Answers

  • Posting this response on behalf of Madhan: Time to live (TTL) can be set at the collection level and the TTL value can be overridden at the document level.

    For your scenario, would the following approach solve your requirement?

    1. Set collection level defaultTTL = Infinite. This means all documents under the collection have an infinite TTL.
    2. Set the document level TTL = <Finite Interval> for those documents that match the search conditions. This can be done during document insertion from your application or via a pre-trigger.
    Thursday, July 14, 2016 4:13 AM

All replies

  • Posting this response on behalf of Madhan: Time to live (TTL) can be set at the collection level and the TTL value can be overridden at the document level.

    For your scenario, would the following approach solve your requirement?

    1. Set collection level defaultTTL = Infinite. This means all documents under the collection have an infinite TTL.
    2. Set the document level TTL = <Finite Interval> for those documents that match the search conditions. This can be done during document insertion from your application or via a pre-trigger.
    Thursday, July 14, 2016 4:13 AM
  • Great! This will do, thanks Mimi and Madhan!

    Fan

    Thursday, July 14, 2016 4:53 PM