Search code examples
azure-cosmosdbazure-rest-api

Cosmos DB REST API not returning data for cross partition query for newly created collection


I've been using the Cosmos DB REST API to query collections, and I've encountered an issue with a specific query when the cross partition is set to true. Strangely, the query works for older collections but not for the ones created in the past 5-6 months. All collections were created using the same scripts.

The only recent change we made to our Cosmos DB is enabling AAD-only authentication. Consequently, our script now retrieves the AAD token instead of the master key. Could this change be affecting the query's behavior in the new collections?

Note : Same query works for both old and new collection in azure cosmos data explorer https://cosmos.azure.com/?feature.enableAadDataPlane=true

Here's a screenshot of postman REST API call

Headers : enter image description here

Request and Response : enter image description here


Solution

  • When executing queries, check the x-ms-continuation header in the response.

    If the header is present and has some value (based on the comments it's {"token":null,"range":{"min":"05C1B9CD673390","max":"05C1C9CD673390"}}), then you need to use it on a next request to keep consuming the query results.

    Queries can have empty pages, particularly cross-partition ones.

    Reference: https://learn.microsoft.com/azure/cosmos-db/nosql/query/pagination#continuation-tokens