Adventures with Cosmos: Delete All Documents

Cosmos DB

When testing my Cosmos database I often like to reset the containers, or in other words, delete all the existing documents.

Unfortunately, there is no way to do a DELETE * FROM in Cosmos, at least not yet.

I know I could create a Console Application or Azure Function to do this, but I was hoping not create another .NET Project or Resource in Azure.

My choice, add a Jupyter Notebooks.

Built-in Jupyter notebooks in Azure Cosmos DB enable you to analyze and visualize your data from the Azure portal. This article describes how to enable this feature for your Azure Cosmos DB account.

To enable Jupyter Notebooks follow the instructions at Enable notebooks in the Azure Cosmos DB account (preview) | Microsoft Docs.

In the notebook, paste the following code:

Replace the values of YOUR_CONTAINER_* and YOUR_PARTITION_KEY_* with the appropriate values, e.g. customers and \customerId.

You can then Run the code and your containers will be recreated.

Keep in mind, I only do this is my development environment, and in most cases, using Shared Throughput.

If you have a another way, please share!

Leave a Reply

Your email address will not be published.