'标识'绑定到CosmosDB输入时需要

时间:2018-03-14 12:05:17

标签: 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.

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

1 个答案:

答案 0 :(得分:1)

看起来不支持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());
}