8
votes

I'm trying to insert a JSON document into DocumentDB via REST, using PHP (which lacks an official API wrapper). Now, it seems that a partition key has become mandatory for any collection in DocumentDB, but i cannot find the REST API documented.

I get the following error in return:

PartitionKey extracted from document doesn't match the one specified in the header

The JSON document I'm trying to insert looks as follows:

{ id:"1", ... "domain":"domain.com" }

In Azure, I have defined the collection with the following partition key:

/domain

And when sending the REST request, I send along the following header:

x-ms-documentdb-partitionkey: [ "domain" ]

What am I missing here?

1
You would need to specify the partition key value and not the attribute i.e. you would write x-ms-documentdb-partitionkey: [ "domain.com" ]. Please try with this.Gaurav Mantri
It worked!! Thanks a lot! (Please add your reply as an answer - not comment - so I can set accepted/solved)erlangsec
Clarification: Partition keys are required for partitioned collections, not for single-partition collections.David Makogon

1 Answers

9
votes

For x-ms-documentdb-partitionkey value you would need to specify the partition key value ("domain.com") and not the partition key attribute ("domain").

x-ms-documentdb-partitionkey: [ "domain.com" ]

Once you do this, documents matching this partition key value will be returned.