databaseazureazure-cosmosdb

Check whether the partition key exists in the collection for CosmosDB


Is there any way to check whether the partition key exists within a collection for CosmosDB?

For example, the available partition keys are states in the US such as WA, NY, MA, etc.. Is there any SQL statement for CosmosDB to check whether NY is part of the partition key in the collection?

Let's say if it is impossible, is there any way to return a list of partition keys in the collection?


Solution

  • You can try something like

    SELECT DISTINCT myColl.partitionKey FROM myColl
    

    which will return the unique values of the partitionKey. Replace partition key with what you have as a partitionKey in your collection