Search code examples
azurenestjsazure-cosmosdb

CosmosDB cannot delete items with ttl


I have an Azure CosmosDB emulator running, which I'm accessing via the @nestjs/azure-database library. The DB has a container with a ttl set to five minutes. For some reason when either the container or the item have a ttl it becomes impossible to delete them manually. Any attempt at doing so results in a Resource Not Found error. The code I'm running for testing this is

await this.container.items.create({id: '1'});
await this.container.item('1').read();
await this.container.item('1').delete();

The read operation goes through fine, but the delete always fails and the item remains in the DB, visible on the emulator's explorer. I cannot see anything in the documentation that would say that deleting an item manually is not possible if it has a ttl. How would one preemptively remove an item with a ttl that hasn't yet expired?


Solution

  • The issue ended up having nothing to do with TTL, after a step by step process of mutating a working example I ended up discovering that despite the partitionKeyValue being an optional parameter in @azure/cosmos any mutation on an item, such as delete or patch will throw a 404 unless the partitionKeyValue is provided. Hopefully this saves someone else some time.