question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Equivalent for az cosmosdb collection exists

See original GitHub issue

Is 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

  1. Continuing to use the deprecated variant for now.
  2. 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shurdcommented, Mar 24, 2020

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.

0reactions
shurdcommented, Jun 18, 2020

The change has been merged and will be in the next release

Read more comments on GitHub >

github_iconTop Results From Across the Web

az cosmosdb collection - Microsoft Learn
az cosmosdb collection delete. Deletes an Azure Cosmos DB collection. ; az cosmosdb collection exists. Returns a boolean indicating whether the collection exists ......
Read more >
az cosmosdb collection - commands deprecated · Issue #15921
This 'az cosmosdb collection' is marked as deprecated, however where is the non-deprecated sql equivalent of this command?
Read more >
Querying in Azure Cosmos DB
Azure Cosmos DB SQL API accounts provide support for querying items using the ... For example, SELECT food.id and SELECT food[“id”] are equivalent....
Read more >
Interact with Azure Cosmos DB with PowerShell - 4sysops
Next, sign into Azure, and set your subscription context if necessary: ... Now, we tap into the Az.CosmosDB PowerShell module where all the ......
Read more >
Deploy a new CosmosDB and set it up using scripts
I've been working on automatically deploying an Azure CosmosDB and ... if collection exists: $collectionName" if ((az cosmosdb collection ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found