How to automatically expire documents, based on a field's value, with Azure Cosmos DB API?

Viewed 91

I have a collection in cosmos db and I need to implement TTL based on its "expiration" field, which is a date. My documents should expire 7 days post the expiration date. According to documentation, cosmos db api limits the ability to do so. I want to achieve something like below for my collection. How can I do that?

db.collection.createIndex(
    {
        Expiration: 1
    },
    {
        name: "Expiration_1",
        expireAfterSeconds: 604800
    }
);
0 Answers
Related