I want to connect my Azure Function with my CosmosDB collection using DocumentDB output binding.
My Function:
public static class HttpTriggerSave
{
[FunctionName("HttpTriggerSave")]
public static void Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, [DocumentDB("dbName", "collectionName", Id = "id")] dynamic outputDoc, TraceWriter log)
{
outputDoc = new
{
Text = "text",
id = Guid.NewGuid()
};
}
}
My local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": "",
"AzureWebJobsServiceBus": "Endpoint=sb://<namespace>/;SharedAccessKeyName=<keyname>;SharedAccessKey=<key>",
"AzureWebJobsDocumentDBConnectionString": "mongodb://..."
}
}
However I get every time the same error:
mscorlib: Exception while executing function: HttpTriggerSave. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'outputDoc'. Microsoft.Azure.Documents.Client: Value cannot be null.
Parameter name: authKeyOrResourceToken.
How can I fix that?

CosmosDBTriggerattribute must be used when I want to trigger the function in response to database changes. I want to do the opposite: I want to bind the function to CosmosDB so that I can modify the database within the function assigning the new document tooutputDocvariable - Alessio Innocenzi