BadRequest exceptions from java sdk `readMany` request when container partition key path has quote-escaped field name

notnotscott 0 Reputation points
2025-01-22T17:36:00.9+00:00

When I create a container using a partition key path of "/id", add some documents to the container (say, 20) and read back the documents with a CosmosContainer.readMany operation (java sdk for NoSQL), I get the documents back with no problem. However, if I instead create the container with partition key path of "/\"id\"", the same operation gets a BadRequest exception. Does anyone have any explanation for this, or have seen any other difference in the formatting of the partition key path?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,745 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Mahesh Kurva 2,670 Reputation points Microsoft Vendor
    2025-01-22T21:16:11.1233333+00:00

    Hi @notnotscott,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    As I understand it, the issue you're facing is likely due to the incorrect formatting of the partition key path.

    In Azure Cosmos DB, the partition key path should be specified without any additional escape characters or quotes. When you use "/"id"", the extra quotes and escape characters cause the partition key path to be misinterpreted, leading to a Bad Request exception.

    Here are a few key points to consider:

    1. The partition key path should be specified as "/id" without any additional quotes or escape characters. This ensures that the partition key is correctly recognized and used by Cosmos DB.
    2. Ensure that the partition key value in your documents matches the partition key path specified when creating the container. Any mismatch can lead to errors.
    3. A BadRequest (400) error can occur if the partition key value is of an invalid type, if the partition key path is incorrect, or if the partition key value does not match the expected value in the document.

    For more information, please refer the document: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/troubleshoot-bad-request

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.