1
votes

I'm currently creating a C# function app on Azure, activated by a timer trigger and with a CosmosDB input. For this app the function.json is

{
  "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
}

and the function code is the following one

#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);
}

If I save this code I receive this error from the console log

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.

Using the id in the binding I haven't this error but I think there is something wrong because I would like to select the whole collection not a single document. Anyone can help?

1

1 Answers

1
votes

It looks like IReadOnlyList is not supported. Change your function to

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());
}