Is there any way to empty container using Query?

Lisha Tawar 1 Reputation point


I need to empty container using a single query in cosmos db. Is there any way to empty container in No SQL?
If yes, then which code should I use to clean container in java. Please help me to achieve this.

Is there any documentation available for that?


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

2 answers

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,012 Reputation points Microsoft Employee

    Hi, @Lisha Tawar Welcome to the Microsoft Q&A platform, thanks for posting the question
    If I understand correctly you want to delete the container using a single query in Cosmodb NOSQL API
    Which Java client are you using? check this document on Java SDK and sample code on github
    however, you should be able to configure the TTL from the Portal the best ways is to delete & recreate the container, or set the TTL to 0 , or do a SELECT * and then iterate through each result, get the ID and delete with the method posted here
    You go to the container that you need, Set the TTL to 1 second and all documents that are older than 1 second will get deleted from the container

    I hope this information helps.


  2. Sonny Gillissen 3,351 Reputation points

    No, unfortunately there’s not. The solution above could work, or just delete and recreate the container.

    0 comments No comments