how to set ttl on collection of cosmos db while i am creating collection through cosmos db REST API

Katakia, Akshara 21 Reputation points
2020-09-28T04:31:07.207+00:00

I am trying to set TTL on collection , I want to set it through code as i am creating collection through making call to cosmos db REST API , I don't have any idea what property name and where to set in
In body , in header , as I don't want to set it through azure portal,

I refereed https://video2.skills-academy.com/en-us/rest/api/cosmos-db/collections but here there is no indication of ttl property -how to set it where to set it

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,632 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anurag Sharma 17,606 Reputation points
    2020-09-28T06:50:15.127+00:00

    Hi KatakiaAkshara-9774, welcome to Microsoft Q&A forum. We will be glad to assist you there.

    If you want to set the ttl at the container level, you need to add it in the body like below. Please note here I am creating a new collection with 'tempcoll' name and ttl defined as 150 seconds.

    {  
        "id": "tempcoll",  
        "defaultTtl": 150  
    }  
    

    When I check it on Azure Portal, its set correctly as below screenshot:

    28629-image.png

    I used Postman to post the rest api requests.

    Please let us know if this helps or else we can discuss more on the same.

    ----------

    if this solves your query, please "Accept Answer" as it could help others having similar issue.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.