Hary
Hary

Reputation: 5818

Postman: Cannot Create Document with Azure MongoDB API

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?

Upvotes: 0

Views: 1092

Answers (1)

Chris Anderson
Chris Anderson

Reputation: 8505

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.

Upvotes: 2

Related Questions