从 DocumentDB 读取文档时出现关于 "Partition Routing Information" 的异常

An exception about "Partition Routing Information" in reading a document from DocumentDB

你见过这种异常信息吗?

Partition routing information cannot be extracted from the query when running in a 32-bit process. To complete your query and avoid this exception, ensure that your host process is 64-bit. For Executable applications, this can be done by unchecking the "Prefer 32-bit" option in the project properties window, on the Build tab. For VSTest based test projects, this can be done by selecting Test->Test Settings->Default Processor Architecture as X64, from Visual Studio Test menu option. For locally deployed ASP.NET Web applications, this can be done by checking the "Use the 64 bit version of IIS Express for web sites and projects", under Tools->Options->Projects and Solutions->Web Projects.

当我想从 DocumentDB 读取文档时,收到此异常消息。 C# 中检索文档的代码如下所示(也检查了没有 FeedOption 的情况):

FeedOptions queryOptions = new FeedOptions { EnableCrossPartitionQuery = true };
var conv = db.Client.CreateDocumentQuery<Model.Conversation>(
UriFactory.CreateDocumentCollectionUri(db.DatabaseName, db.CollectionName), queryOptions)
.Where(f => f.Id == "conversationId");

// the exception happens here
foreach(Conversation f in conv)
{
    Debug.Print(f.Name);
}

在上面,db 是一个存储库,我确信 Client 已经正确启动,因为我可以同时将文档插入 DocumentDB。

此外,您还可以看到对话模型:

public class Conversation
{
    [JsonProperty(PropertyName = "id")]
    public string Id { get; set; }
    public string Name { get; set; }
    [JsonProperty("cid")]
    public string CID { get; set; } // defined as a partition key
}

我应该提到在 DocumentDB 中有一个文档 Id == "conversationId",下面的代码在这种情况下有效,但这不是解决方案,因为我想在 Name 属性 也一样,不仅仅是 Id:

Document doc = await db.Client.ReadDocumentAsync(
         UriFactory.CreateDocumentUri(db.DatabaseName, db.CollectionName, "conversationId"),
         new RequestOptions { PartitionKey = new PartitionKey("partitionKey") });
Conversation conv = (Conversation)(dynamic)doc;

这是程序集版本问题和异常,也显示了可能的修复解决方案。

修复该问题有三种可能的替代方法。

  1. 在 VS2015 中更改项目设置 -> 工具 -> 选项 - 项目和解决方案 -> Web 项目并勾选 "Use 64bit version of IIS..."

  1. 您可以更改 IIS 池设置并允许 32 位应用程序,如下图所示。

  1. 您还可以更改项目构建属性并将目标平台设置为 "Any CPU"。

我找到了解决方案。在问题中,使用了 1.11 版本的 Microsoft.Azure.Document 库。正如我在 this link 中发现的那样,CreateDocumentQuery 已被废弃,显然 api 已被更改。所以,当我降级到 1.10 版时,一切正常。因此,我对此感到非常高兴!

因此,CreateDocumentQuery 在 1.11 版本中已被废弃,您应该为每个集合定义一个 partitionKey,其结果是您不能再使用 CreateDocumentQuery,除非您降级到1.10版本以下。 另外,我认为这是这个版本中的一个错误,应该报告。