Tony Gutierrez
Tony Gutierrez

Reputation: 771

Cosmos DB succeeds and fails on randomly on the same query, saying they are cross partition when they aren't

I have a collection with the partition key "flightConversationId".

I am doing a very simple query, BY THE PARTITON KEY FIELD

SELECT * from root WHERE root.flightConversationId="b36d13c0-cbec-11e7-a4ad-8fcedf370f98"

When doing this query via the nodeJS SDK, it will work one second, and fail the next with the error:

Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.

I realize I could enable cross-partition querying, but I do not need cross partition queries. What is going on???

Upvotes: 4

Views: 1065

Answers (2)

Tony Gutierrez
Tony Gutierrez

Reputation: 771

This situation seemed to resolve itself over time.

My theory is that when we deleted a collection and recreated it with a new partition key, it took a long time for all remnants of the original collection to really be deleted from the cloud, and that some requests were going to the "old" collection that had the same name as the "new".

Upvotes: 3

Pete M
Pete M

Reputation: 2048

You have to explicitly scope the query to a partition by providing an FeedOptions or RequestOptions class with a partitionKey property. Using the PartitionKey in your where clause isn't enough without that explicit scope. This is for C# but should be same object model:

https://learn.microsoft.com/en-us/azure/cosmos-db/documentdb-partition-data

Document result = await client.ReadDocumentAsync(
  UriFactory.CreateDocumentUri("db", "coll", "XMS-001-FE24C"), 
  new RequestOptions { PartitionKey = new PartitionKey("XMS-0001") });

jsDoc:

http://azure.github.io/azure-documentdb-node/global.html#RequestOptions http://azure.github.io/azure-documentdb-node/global.html#FeedOptions

Upvotes: 1

Related Questions