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

标签 c# azure azure-functions azure-cosmosdb

我目前正在 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/

相关文章:

c# - 在 vb.net 中运行基于声音 VU 级别的脚本

sql - 当我减小半径时,为什么针对 SQL Azure 中的空间索引的空间查询需要更长的时间?

c# - 使用 AWSSDK.S3 通过 C# 验证 Amazon S3 存储桶

azure-functions - 在本地运行 Azure Function 时无法读取 local.settings.json 文件

azure - 如何在 Azure Function 中定义 Azure Blob 存储触发器的路径

azure - 无法使用 Azure Function App 创建 API

C# - Linq 将泛型列表转换为自定义类

c# - 为什么我的自定义 DisplayFor 模板实际上没有在此处呈现?

c# - 用于验证的正则表达式模式 - 尝试压缩正则表达式中的重复模式

azure - 为什么 Azcopy 适用于 Azure 中的小文件而不适用于大文件?