Home > Back-end >  How should I extend the TTL of a document in Azure CosmosDB using the Python SDK?
How should I extend the TTL of a document in Azure CosmosDB using the Python SDK?

Time:02-10

I'm working with a Cosmos DB database with the SQL API. I have a container with TTL policy of 6 months. When a certain action is taken, my code receives an id and need to extend the deletion time for the item with that id in that container to now 6 months. What is the recommended way to do this? An empty upsert?

  • I can assume the document exists.
  • The documents only need to be deleted in approximately six months. I'm not worried about exact timing.
  • I'm using the Python SDK. I looked through the documentation, but I could not find anything like an "extend" operation.
  • Should I not be leveraging the TTL? Should I be doing something else?

CodePudding user response:

Any update on the document resets the timestamp of that document (the _ts property).

The TTL basically acts based on that value.

So in your case, a simple Replace operation over that document would reset the timestamp so it would effectively be deleted 6 months after this last update.

  • Related