8

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?

3
  • 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. Commented Mar 21, 2017 at 6:36
  • It worked!! Thanks a lot! (Please add your reply as an answer - not comment - so I can set accepted/solved) Commented Mar 21, 2017 at 7:19
  • 3
    Clarification: Partition keys are required for partitioned collections, not for single-partition collections. Commented Mar 21, 2017 at 11:25

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.