首页 > 解决方案 > Azure Cosmos DB:按 GUID 检索文档

问题描述

我在 Cosmos DB 容器中存储了一个带有 GUID 的文档。但是,当我尝试使用Where()子句检索同一文档时,它无法返回该文档。

这是我查询文档的 C# 代码:

var application = await client
  .CreateDocumentQuery<Document>(collectionLink, feedOptions)
  .Where(d => d.Id == "b0e6b18a-54rgf-497d-45g7-bcb17afbdtyh")
  .Where(d => d.Type == "application")
  .Where(d => d.DeletedDateTime == null)
  .AsDocumentQuery()
  .ExecuteNextAsync<Document>(cancellationToken)
  .ConfigureAwait(false);

这是 Azure Cosmos DB 中的示例 Json 文件:

{
    "id": "b0e6b18a-54rgf-497d-45g7-bcb17afbdtyh",
    "Type": "application",
    "ApplicationId": "b0e6b18a-54rgf-497d-45g7-bcb17afbdtyh",
    "Name": "test",
    "Description": "test application.",
    "Company": "test",
    "OwnerEmailId": "xyz@xyz.com",
    "CreatedDateTime": "",
    "ModifiedDateTime": "",
    "DeletedDateTime": null,   
    "Resources": [],
    "_rid": "removedId",
    "_self": "removedId",
    "_etag": "removedID",
    "_attachments": "attachments/",
    "_ts": 1567604515
}

在最终输出中,没有匹配的记录。什么不见​​了?

重要的!此代码在我的开发环境中运行。但它在测试环境中失败。

标签: c#azureazure-cosmosdb

解决方案


推荐阅读