Equivalent for az cosmosdb collection exists
See original GitHub issueIs your feature request related to a problem? Please describe.
I am writing a script that will update a property of a Cosmos DB container and perform a variety of other operations, but only if the container already exists. I’m not interested in getting an error if the container doesn’t exist as in my case it doesn’t really represent an error condition.
I am using the command az cosmosdb sql container update for this, which works fine. However, I can’t find a way to test if the container exists or not. The show command returns an error rather than no result if it doesn’t exist. (Side note: in my Google searches, many people claim that show would return nothing if the object doesn’t exist and is a good method to test for existence. I have no reason to think these people are all incorrect which probably means the contract for the show command is inconsistent across the Azure CLI) I don’t see an exists command at all in the help, and even tried without success to see if perhaps it was undocumented.
However, I did find exists within the collection subgroup of cosmosdb. This does what I want it to, however I get the following message:
This command has been deprecated and will be removed in a future release. Use 'cosmosdb sql container, cosmosdb mongodb collection, cosmosdb cassandra table, cosmosdb gremlin graph or cosmosdb table' instead.
This command is implicitly deprecated because command group 'cosmosdb collection' is deprecated and will be removed in a future release. Use 'cosmosdb sql container, cosmosdb mongodb collection, cosmosdb cassandra table, cosmosdb gremlin graph or cosmosdb table' instead.
Doh - took me back full-circle. Not helpful.
Describe the solution you’d like
Command az cosmosdb sql container exists returns true if the container exists, and false if not. The same required parameters would need provided as with the other commands of the container subgroup.
Describe alternatives you’ve considered
- Continuing to use the deprecated variant for now.
- Determine existence of the container based on error detection (YUCKY!!!)
Additional context
In my opinion, the exists command should be a standard part of the CLI contract of any resource type, and any subgroup where the concept of “existence” is relevant. If I should change my thinking around this, please explain in your replies.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
Hi @bojingo, thank you for opening this issue. When adding the new commands, we did not create an “exists” command. As you indicate, currently you must use the “show” command and determine if there was an error. We will work on adding an “exists” option. We are tracking this internally as work item 672701 and have an ETA of the end of April.
The change has been merged and will be in the next release