Marco Jr
Marco Jr

Reputation: 6796

Storing Partition Keys on CosmosDB

The concept is very straight away. Not difficulty to understand. But I can't find some practical examples... I've this json...

{
    "agendaId": "688c99bc-c756-4b8f-9c39-60246c0ea66e",
    "postId": "f07f16e5-e7d6-441e-bc1d-82ac671e0f63",
    "name": "john doe"
}

And I defined this partition: /agendaId/postId

And then I inserted the item.

But I can't see any data on my CosmosDB Container Browser on the column of the partition key - I just can see the autogenerated Id...is this expected ?

enter image description here

Upvotes: 0

Views: 271

Answers (1)

Matias Quaranta
Matias Quaranta

Reputation: 15603

/agendaId/postId means that the value is nested. The JSON to match that definition should be:

{
    "agendaId": {
            "postId": "f07f16e5-e7d6-441e-bc1d-82ac671e0f63",
    },

    "name": "john doe"
}

The / on the definition defines the level of nesting, so /attr1/attr2/attr3 would mean that the value is in attr3 that exists in attr2 which exists in attr1:

{
    "attr1": {
        "attr2": {
            "attr3": "the value"
        }
    }
}

In your case, if you used, for example /agendaId is just the first level of attributes, or /postId. Both would pick up the value of the attributes in your document.

Reference: https://learn.microsoft.com/azure/cosmos-db/partitioning-overview#choose-partitionkey

Snapshot of a text explaining the concept of nested from the linked document

Upvotes: 1

Related Questions