Cosmosdb Bind in Azure Functions Local

Asked

Viewed 42 times

2

How to bind Azure Cosmodb to Visual Studio in Azure Functions?

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

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);
                }
            }
        }
    }
  • Show us what you’ve done, and what error is occurring, so we can help.

  • Read this post to understand how the auto reply https://answall.com/help/self-answerworks

  • @Was Uzumakiartanis worth the tip? I’m not getting an answer to my own question... Is it because it’s pending?

  • Yes, when a question is marked as [pending], [duplicated], [closed] it is impossible for you to make changes to it @miltoncamara.

  • @Uzumakiartanis I got it... I’ll wait for it to be reopened then, one more point! Thank you very much :)

  • It was voted to reopen @miltoncamara and now you can rewrite the post correctly. Make your edits and leave your post within the site standard.

Show 1 more comment

1 answer

3


To bind to a Function you need to add the following configuration:

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.