CosmosDB - Delete item after certain time with condifiton

Viewed 37

I would like to delete a certain item from the DB with a condition:

Delete this item after 72 hours of its creation if c.email_verified is false

1 Answers

You can certainly do this via the Node SDK, you need to set the TTL at the Item creation by adding a condition, sample code would be

const itemDefinition = {
  id: "doc",
  name: "sample Item",
  email_verified: false 
}; 

if(!itemDefinition.email_verified){
       itemDefinition.ttl = 60 * 60 * 24 * 3; //72 hours
}

and then create the item. Here is a sample

Related