0

When creating the document with Azure Cosmos DB: MongoDB API, I am facing the below issues which varies on parameters.

When creating collection UserProfile, I've created it with Partition Key username.

Request1: - Without Partition Key

Headers:

x-ms-documentdb-is-upsert: true

Body:

{"username": "test"}

Issue:

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

Request2: - With Partition Key

Headers:

x-ms-documentdb-is-upsert: true
x-ms-documentdb-partitionkey: ["username"]

Body:

{"username": "test"}

Issue:

One of the specified inputs is invalid

Request3: - With Partition Key & id specified in body

Headers:

x-ms-documentdb-is-upsert: true
x-ms-documentdb-partitionkey: ["username"]

Body:

{"id": "test", "username": "test"}

Issue:

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

In any case,

I am not able to create the document. What are the necessary parameters to create the document which has partition specified?

1 Answer 1

2

Two points:

  1. If you're using the Mongo API, you should not use the REST API. While it's technically possible, it is not supported to use both together. 100% do not recommend.

  2. partition key needs to be the partition key value, not the path itself, so it would be "test", not "username". It already knows that "username" is the path.

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.