Is there any way to empty container using Query?

Lisha Tawar 1 Reputation point
2022-11-15T13:11:43.927+00:00

Hello,

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?

Thanks.

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

2 answers

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,542 Reputation points Microsoft Employee Moderator
    2022-11-15T14:25:22.357+00:00

    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
    https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-time-to-live?tabs=dotnet-sdk-v3
    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.

    Regards
    Geetha


  2. Sonny Gillissen 3,751 Reputation points Volunteer Moderator
    2022-11-27T21:17:21.933+00:00

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

    0 comments No comments

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.