Bind of CosmosDB at Azure Functions Local

2

How to do Bind Azure CosmoDB by Visual Studio in Azure Functions?

Note the code below, the inputDocument parameter would be the CosmosDB Bind. When we create the direct function in the Azure portal, it already does this automatically because it already creates the connections in the local.settings.json file.

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System.Collections.Generic;

    namespace CDPCompare
    {
        public static class CallWS
        {
            [FunctionName("TimerTriggerCSharp")]
            public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log, IEnumerable<dynamic> inputDocument)
            {
                foreach(var item in inputDocument)
                {
                    log.Info(item);
                }
            }
        }
    }
    
asked by anonymous 17.08.2017 / 02:15

1 answer

3

To do Bind in a Function you need to add the following configuration:

1 - Install the package Nuget Microsoft.Azure.WebJobs.Extensions.DocumentDB

2 - Include the [DocumentDB("%DatabaseName%", "MyCollection")] attribute followed by the IEnumerable<dynamic> inputDocuments

3 - Add the CosmosDB connection string in the file local.settings.json "AzureWebJobsDocumentDBConnectionString":"STRING DE CONEXÃO COSMOS DB"

    
17.08.2017 / 19:13