gpt4 book ai didi

c# - 绑定(bind)到 CosmosDB 输入时需要“Id”

转载 作者:行者123 更新时间:2023-12-03 03:00:33 24 4
gpt4 key购买 nike

我目前正在 Azure 上创建一个 C# 函数应用,由计时器触发器和 CosmosDB 输入激活。对于此应用程序,function.json

{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"type": "documentDB",
"name": "documents",
"databaseName": "database",
"collectionName": "collection",
"connection": "hellocloud_DOCUMENTDB",
"direction": "in"
}
],
"disabled": false
}

函数代码如下

#r "Microsoft.Azure.Documents.Client"

using System;
using Microsoft.Azure.Documents;
using System.Collections.Generic;

public static void Run(TimerInfo myTimer, IReadOnlyList<Document> documents,
TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
log.Info("Documents modified " + documents.Count);
}

如果我保存此代码,我会从控制台日志中收到此错误

2018-03-14T10:31:36.739 [Info] Compilation succeeded.

2018-03-14T10:31:37.425 [Error] Microsoft.Azure.WebJobs.Host: Error indexing
method 'Functions.HelloCloudFunction'.
Microsoft.Azure.WebJobs.Extensions.DocumentDB: 'Id'
is required when binding to a IReadOnlyList`1 property.

在绑定(bind)中使用 id 我没有出现此错误,但我认为有问题,因为我想选择整个集合而不是单个文档。有人可以帮忙吗?

最佳答案

看起来IReadOnlyList不受支持。将您的功能更改为

public static void Run(TimerInfo myTimer, IEnumerable<Document> documents,
TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
log.Info("Documents modified " + documents.Count());
}

关于c# - 绑定(bind)到 CosmosDB 输入时需要“Id”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49277379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com