As Rob Reagan's answer already clarified, there is a difference between clearing all items from a container and clearing all items from a database. However, deleting the whole container to remove all items could lead to problems in certain scenarios. Often, the containers are defined and created via infrastructure as code (IaC) like Terraform or directly in code via the Cosmos client. When you delete the container, you must ensure that you create it with the same configuration again or rerun the IaC. If a Cosmos client is running when you delete a container (e.g., in a deployed service), the client would return errors regarding the existence of the container (e.g. 404 NotFound
) while the container is absent.
Since for now there is no way to delete all items from a container in the Azure portal, you could use the already mentioned workarounds.
- James's answer: Set the TTL of the container.
- ArunkumaarCN's answer: Using stored procedures.
Another way would be to use an external tool that leverages the Cosmos client to delete all existing container items. Since I faced the same problem and didn't come across such a tool, I built my own Visual Studio Code Extension. If you like, try it out for yourself and install it from the marketplace. You can also clone the repository and modify it to match your needs.