2

I am using RESTfull HTTP request to fetch the Partition Key of a collection. I am doing:

        response = client.GetStringAsync(new Uri(baseUri, resourceLink)).Result;
        var data3 = (JObject)JsonConvert.DeserializeObject(response);
        if (data3["partitionKey"] != null)
        {
            string partitionKey = data3["partitionKey"]["paths"][0].ToString();
            string PartitionKey = partitionKey.Substring(1);
            return PartitionKey;
        }

Is there a more efficient way to do this? Do their SDK's have a direct way to fetch the Partition Key?

UPDATE

My response on fetching partition key range is:

item={ "_rid": "lIB0ALrgyAACAAAAAAAAUA==", "id": "0", "_etag": "\"00000000-0000-0000-0318-18b49de501d4\"", "minInclusive": "", "maxExclusive": "FF", "ridPrefix": 0, "_self": "dbs/lIB0AA==/colls/lIB0ALrgyAA=/pkranges/lIB0ALrgyAACAAAAAAAAUA==/", "throughputFraction": 1.0, "status": "online", "parents": [], "_ts": 1528895512 }

How does this take me close to finding out what the partition key is?

das
  • 201
  • 1
  • 3
  • 10

3 Answers3

1

Did you try with standard cosmos .Net client ?

            var col = await CosmosClient.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(
            dataBaseName,
            collectionName));

            var pathes = col.Resource.PartitionKey.Paths;
Olha Shumeliuk
  • 720
  • 7
  • 14
0

The .NET SDK gives you the ability to query partition ranges using ReadPartitionKeyRangeFeedAsync.

Get all the Partition Keys in Azure Cosmos DB collection

So yes, the .NET SDK gives you a means for finding partition keys.

Mike Ubezzi
  • 1,007
  • 6
  • 8
  • 1
    Yeah I understand how I can get the partition key range. But how do I get the name of the partition key from there? I get this response: `item={ "_rid": "lIB0ALrgyAACAAAAAAAAUA==", "id": "0", "_etag": "\"00000000-0000-0000-0318-18b49de501d4\"", "minInclusive": "", "maxExclusive": "FF", "ridPrefix": 0, "_self": "dbs/lIB0AA==/colls/lIB0ALrgyAA=/pkranges/lIB0ALrgyAACAAAAAAAAUA==/", "throughputFraction": 1.0, "status": "online", "parents": [], "_ts": 1528895512 }` How does this take me close to finding the Partition Key of the specified collection? – das Jun 20 '18 at 06:37