Forum Discussion
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.
With Regards,
Nitin Rahim
3 Replies
- JillArmour
Community Manager
SaranyaSriram or mannu2050 can you help here?
- mannu2050
Microsoft
JillArmour 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!
- nitinrahimBrass ContributorThank you.
With Regards,
Nitin Rahim