1
votes

EDITED with my own progress.

I am trying to use DocumentDb within an Azure Function that I am writing with the new Visual Studio Tooling which allows me to build and deploy a dll. My function.json file is created by the tooling so I don't think I can create my binding in function.json I have to use Attributes.

I have added the Microsoft.Azure.Webjobs.Extensions.DocumentDB package to my solution. I then have a function signature:

public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] 

HttpRequestMessage req,
[DocumentDB("database", "collection"ConnectionStringSetting = "conn", Id = "w", PartitionKey = "customer")) DocumentClient docdbcli,
TraceWriter log)

In method body I have:

await docdbcli.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("customerdocumentversionsdb", "snapshots"), new
        {
            id = "edse",
            customer = "expedia",
            document = Converter.Serialize(jliff),
            version = "sourceedited"
        });

The function.json compiled by the tooling is:

{
"bindings": [
 {
  "type": "httpTrigger",
  "methods": [
    "get",
    "post"
  ],
  "authLevel": "function",
  "direction": "in",
  "name": "req"
},
{
  "type": "documentDB",
  "databaseName": "customerdocumentversionsdb",
  "collectionName": "snapshots",
  "createIfNotExists": false,
  "connection": "conn",
  "id": "w",
  "partitionKey": "customer",
  "direction": "out",
  "name": "docdbcli"
},
{
  "name": "$return",
  "type": "http",
  "direction": "out"
}
],
"disabled": false,
"scriptFile": "..\\MtWithRulesFunctionApp.dll",
"entryPoint": "MtWithRulesFunctionApp.PreEditSource.Run"
}

My documents are not written to the db probably because the binding about is specified as out.

3
Generally you shouldn't edit questions to a significantly different one...Mikhail Shilkov

3 Answers

3
votes

You need to reference Microsoft.Azure.WebJobs.Extensions.DocumentDB NuGet package, use the namespace

using Microsoft.Azure.WebJobs.Extensions.DocumentDB;

and then decorate your function parameter with DocumentDB attribute.

0
votes

Turned out to be a problem with v1.5 of the library. Using 1.4 works.

0
votes

It looks like there was a breaking change in DocumentDb. It was done in a minor build version, so it violated semantic versioning. https://github.com/Azure/azure-webjobs-sdk-script/issues/1679