Forum Discussion
nitinrahim
Oct 20, 2023Brass Contributor
Query to see if a container exists in Cosmos Db
Hi Team, Is there a cosmos query that can be executed in cosmos database to see if a particular container exists in a cosmos database from the portal or at the sdk level? We are using JAVA SDK. ...
JillArmour
Community Manager
Oct 20, 2023SaranyaSriram or mannu2050 can you help here?
mannu2050
Microsoft
Oct 26, 2023JillArmour nitinrahim you can iterate through list of containers and match, https://learn.microsoft.com/en-us/java/api/com.azure.cosmos.cosmosdatabase?view=azure-java-stable#com-azure-cosmos-cosmosdatabase-readallcontainers()
If the intent is to create container before checking the container's existence, https://learn.microsoft.com/en-us/java/api/com.azure.cosmos.cosmosdatabase?view=azure-java-stable#com-azure-cosmos-cosmosdatabase-createcontainerifnotexists(com-azure-cosmos-models-cosmoscontainerproperties-com-azure-cosmos-models-throughputproperties)
Please note it has overload methods and feel free to choose the one suits you.
Hope this helps!
- nitinrahimOct 26, 2023Brass ContributorThank you.
With Regards,
Nitin Rahim