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

試著忘記壹切 提交于 2019-12-12 14:27:27

问题


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???


回答1:


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".




回答2:


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://docs.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



来源:https://stackoverflow.com/questions/47400737/cosmos-db-succeeds-and-fails-on-randomly-on-the-same-query-saying-they-are-cros

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!