a8m / documentdb

Go driver for Microsoft Azure DocumentDB
MIT License
33 stars 25 forks source link

Issue with CreateDocument: "ERROR: BadRequest, Message: {"Errors":["PartitionKey extracted from document doesn't match the one specified in the header"]}" #30

Closed fjanon closed 4 years ago

fjanon commented 4 years ago

It looks like something has changed in the REST API for client.CreateDocument:

ERROR: BadRequest, Message: {"Errors":["PartitionKey extracted from document doesn't match the one specified in the header"]}

My code:

type Place struct { documentdb.Document // Your external fields Id string json:"id,omitempty" Lat int json:"lat,omitempty" }

response, err = client.CreateDocument(selfPlacesCollection, &newplace, documentdb.PartitionKey("lat"))

Any ideas on how to fix that?

Thanks

fjanon commented 4 years ago

Found the fix from this doc:

https://docs.microsoft.com/en-us/rest/api/cosmos-db/create-a-document#example

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

The documentdb.PartitionKey should be the partition key value, not its name:

In my code, documentdb.PartitionKey("lat")) should be documentdb.PartitionKey(42)), 42 being the value of the partition key in the document