【问题标题】:'Id' is required when binding to CosmosDB input绑定到 CosmosDB 输入时需要“Id”
【发布时间】:2018-03-14 12:05:17
【问题描述】:

我目前正在 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 我没有这个错误,但我认为有问题,因为我想选择整个集合而不是单个文档。有人可以帮忙吗?

【问题讨论】:

    标签: c# azure azure-functions azure-cosmosdb


    【解决方案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());
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多