Azure functions 无法分析值'';在Azure函数中作为Cosmos DocumentQuery中的ResourceId

Azure functions 无法分析值'';在Azure函数中作为Cosmos DocumentQuery中的ResourceId,azure-functions,azure-cosmosdb,azure-cosmosdb-sqlapi,Azure Functions,Azure Cosmosdb,Azure Cosmosdb Sqlapi,我有一个Azure函数2.0.12562,在尝试查询CosmosDB时出现以下错误 错误:DoesCommontain失败:无法将值“”解析为 ResourceId.,Windows/10.0.18362 documentdb netcore sdk/2.4.0 宇宙中的一个入口看起来像 { "id": "851a3506-3915-4f7c-9e32-32d927055555", "_rid": "Tg8ZAI-iVnQBAAAAAAAADQ==", "_self":

我有一个Azure函数2.0.12562,在尝试查询CosmosDB时出现以下错误

错误:DoesCommontain失败:无法将值“”解析为 ResourceId.,Windows/10.0.18362 documentdb netcore sdk/2.4.0

宇宙中的一个入口看起来像

{
    "id": "851a3506-3915-4f7c-9e32-32d927055555",
    "_rid": "Tg8ZAI-iVnQBAAAAAAAADQ==",
    "_self": "dbs/Tg8ZAA==/colls/Tg8ZAI-iVnQ=/docs/Tg8ZAI-iVnQBAAAAAAAADQ==/",
    "_etag": "\"0f00e289-0000-0500-0000-5d1676600000\"",
    "Prop_0": "555",
    "Prop_1": "5551234",
    "_attachments": "attachments/",
    "_ts": 1561755555
}
此Azure函数接收POST中的所有DB连接器以及正在工作的DB连接器。 错误在ExecuteExtAsync行上抛出

[FunctionName("DoesCosmosContain")]
    public static async Task<bool> DoesCosmosContain([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
    {
        try
        {
            MyCosmosInformation scaleParams = await MyCosmosInformation.CreateAsync(req);

            // shimming out locals
            string key = scaleParams.CosmosKey;
            string uri = scaleParams.CosmosUri;
            Uri cosmosUri = new Uri(uri);
            string offerLink = scaleParams.OfferLink;

            using (DocumentClient client = new DocumentClient(cosmosUri, key))
            {
                IDocumentQuery<PhoneNumber> query = client.CreateDocumentQuery<PhoneNumber>(offerLink)
                .Where(p => p.AreaCode=="555" && p.Number=="5551234")
                .AsDocumentQuery();

                while (query.HasMoreResults)
                {
                    foreach (PhoneNumber result in await query.ExecuteNextAsync())
                    {
                        return true;
                    }
                }

                return false;
            }
        }
        catch (Exception e)
        {
            string error = $"DoesCosmosContain failed: {e.Message}";
            log.Error(error);
        }
            return true;
    }
电话号码通行证

internal sealed class PhoneNumber
{
    [JsonProperty(PropertyName = "Prop_0")]
    public string AreaCode { get; set; }

    [JsonProperty(PropertyName = "Prop_1")]
    public string Number { get; set; }

    public string ResourceId { get; set; }
}

这是无效的:
client.CreateDocumentQuery(offerLink)

您使用的是一个类似以下内容的offerLink
提供/MYID/
,但是
CreateDocumentQuery
方法需要的是
collectionLink
而不是
offerLink

根据您已有的值,您可以这样构造
CollectionLink

var collectionLink = UriFactory.CreateDocumentCollectionUri(scaleParams.CosmosDbId, scaleParams.CosmosCollectionId)

您还可以向我们展示什么
mycsominsinformation
以及您发布的值吗?我已经更新了问题以获得这些信息。您可以将这个
query.ExecuteNextAsync()
转换成这个
query.ExecuteNextAsync()
并查看实际文档的外观吗。我怀疑这个值不能反序列化。是的!非常感谢,尼克。我已经确认了,修正了我的问题。
internal sealed class PhoneNumber
{
    [JsonProperty(PropertyName = "Prop_0")]
    public string AreaCode { get; set; }

    [JsonProperty(PropertyName = "Prop_1")]
    public string Number { get; set; }

    public string ResourceId { get; set; }
}
var collectionLink = UriFactory.CreateDocumentCollectionUri(scaleParams.CosmosDbId, scaleParams.CosmosCollectionId)