mcamara
mcamara

Reputation: 753

Bind CosmosDB Local Function

Bind Azure CosmosDB on Azure Functions running locally. Any configuration is required to use this feature?

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

Upvotes: 1

Views: 198

Answers (1)

Garth Mason
Garth Mason

Reputation: 8001

Yes, configuration is required for your inputDocument argument.

You need to use this attribute to specify the Cosmos DB name and the collection.

[DocumentDB("%DatabaseName%", "MyCollection")] IEnumerable<dynamic> inputDocuments

To pick up that attribute you need to reference the NuGet package for document DB Microsoft.Azure.WebJobs.Extensions.DocumentDB. Last I checked this NuGet package is still in pre-release so make sure you include that when searching for the package.

enter image description here

Upvotes: 2

Related Questions