1

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.

1
  • Generally you shouldn't edit questions to a significantly different one... Commented Jul 21, 2017 at 16:51

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured that as you were posting your answer, thanks. But now my document is not being written to the database because docdbcli is null.
0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.