0

I am using azure android SDK for adding new records into collection items. We don't have partition keys for our cosmos-DB. so I am passing as null for it.

it will give me the below error

partition key supplied in x-ms-partitionkey header has fewer components than defined in the collection.

Can anyone help me to come out of this?

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
Karan Ekkawala
  • 317
  • 1
  • 11
  • It would help if you edit your question to contain more details, such as the code you wrote for inserting data into Cosmos DB. That said: you cannot create a collection without a partition key (you can specify `/id` since that property always exists, but... you need to specify *something*, when creating your collection). – David Makogon Nov 14 '19 at 13:28
  • @Karan Ekkawala is this issue resolve? – Ali Jan 21 '20 at 07:09
  • Good to see you, yes I have resolved these issues by assigning partition key as mention in the below comments. Let me know if I can help you any more. – Karan Ekkawala Jan 21 '20 at 10:55
  • Hey I am facing the same issuse , still not resolved for me . Can you help . In my db , I have the partition key named "/items" but when I use it , it gives error saying the key does not match – Karunesh Palekar Dec 10 '21 at 10:32

2 Answers2

0

You need to mark the property you're using as the partition key with the @PartitionKey annotation, e.g.:

@PartitionKey
    var testKey = ""

in C#, we use Undefined.Value and everything will be fine.

client.DeleteDocumentAsync(
          UriFactory.CreateDocumentUri(DbName, CollectionName, id), 
          new RequestOptions() { PartitionKey = new PartitionKey(Undefined.Value) });
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Thanks @Sajeetjaran, but we don't have the option in android to set partition Key-value to undefined, but we have another method in which we can pass the partition Key-value but it is TypeOf(String) which will create for us. trying to override SDK methods, let see hope for the best to get the result – Karan Ekkawala Nov 14 '19 at 13:22
0

The azure android SDK required partition key, it not accepting null or empty. Also if you have a bunch of records to store in the cosmos DB, then you must use the partition key other you may face the partition key limit reached the issue in the future. Azure provides a max of 10 GB for a logical partition.

I have created a new collection with the user wise partition and pass the partition key value eg. patitionKey=/.UserID in my object. this will work for me. Also managing partition key limit issue.

so it will be good to use the partition key in advance to avoid the problem in the future.

Karan Ekkawala
  • 317
  • 1
  • 11