2

If I store documents without providing partition key, In this case documentId will be treated as Partition Key of Logical Partition?

If yes: how about Billion logical partitions in that collection? I have query to only look by documentId.

Now inside Document JSON:
I have multiple fields & I have provided /asset as the partitionKey. Is this a composite partition key now: /asset/documentId? or /asset will tel partition to search for documentId from?

enter image description here

Anil Kapoor
  • 644
  • 6
  • 19

2 Answers2

2

If I store documents without providing partition key, In this case documentId will be treated as Partition Key of Logical Partition?

No. If you create a document without Partition Key, document id will not be treated as the partition key. Cosmos DB engine will put all the documents without a partition key value in a hidden logical partition. This particular partition can be accessed by specifying partition key as {}.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • I've never actually tried this, so you can create a document without a pk if a collection has pk set? just tried it. indeed thats the case. weird. I'd probably block that operation on platform level – 4c74356b41 Jun 19 '19 at 09:45
  • 1
    Yes, you can. I was also surprised by that behavior. But the REST API or SDK will not throw any error if the document doesn't contain partition key. I asked Cosmos DB team about this and they told me how to retrieve those documents. I just need to go through my email. Let me do that and update my answer. – Gaurav Mantri Jun 19 '19 at 09:48
  • You are right, I am using SDK to retrieve documents without partition key. – Anil Kapoor Jun 19 '19 at 10:12
  • Without PK data in a logical partition is searchable by id, is that means my query is scanning all logical partitions to find an id?? – Anil Kapoor Jun 19 '19 at 10:13
  • 1
    `Without PK data in a logical partition is searchable by id, is that means my query is scanning all logical partitions to find an id??` - Yes. It's a cross partition query. – Gaurav Mantri Jun 19 '19 at 10:14
  • 1
    This means, if we want id as PK then we should mention at the time of creating collection. this will avoid cross partition query while searching by id. – Anil Kapoor Jun 19 '19 at 10:18
  • You can certainly do that but it's a bad design decision as each logical partition will only contain one document and you're not truly utilizing the power of logical partitioning. – Gaurav Mantri Jun 19 '19 at 10:22
  • Updated my answer and included how to access that hidden logical partition. – Gaurav Mantri Jun 19 '19 at 10:32
1

You define the partition key when you create the collection (according to the screenshot asset is a partition key in your case). If you dont provide a partition key when you create a collection - it will be limited to 10 GB of data (because it wouldn't be able to shard it without partition key).

Only partition key is used to determine the partition of the document. other fields are irrelevant when deciding which partition this document belongs to.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141