ZZZSharePoint
ZZZSharePoint

Reputation: 1351

Combining multiple keys to create a Synthetic partition key in Cosmos db

I am using below code to upload my document in Cosmos Db and I need a partition key which I have to create by combining two key. in this case it will be TypeId and Cvalue. I would like to know how can i create a Synthetic Partition key in my code below. Thanks

var content = JsonConvert.DeserializeObject<JObject>( lines );
var client = new DocumentClient( new Uri( DbInstance ),Key );
await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(
                Database, Collection ),
                content);

    "Classes": {
        "Subjects": {
          "Name": "testA",
          "TypeId": "AS88QW",
          "Public": "No"
        },
        "Sections": {
          "Scopes": true,
          "CValue": [12,12,1]
        }
      }

Upvotes: 1

Views: 1369

Answers (1)

David Makogon
David Makogon

Reputation: 71068

You cannot directly specify multiple different properties as a combined synthetic partition key. You'd need to do the combining yourself, into another property. In your case, you'd be creating a new property that combines Classes.Subjects.TypeId and Classes.Subjects.CValue. Then that new property (whatever you decide to call it) can be specified as your partition key.

Just note that there's nothing automatic here: you need to create this new property when creating your documents. And you'll need to figure out how to represent something like an array (your CValue property) - how you want to turn that into part of the partition key's value.

You can find more information about synthetic partition keys here.

Upvotes: 3

Related Questions