【发布时间】:2017-11-09 15:10:08
【问题描述】:
我想使用 DocumentDB 输出绑定将我的 Azure Function 与我的 CosmosDB 集合连接起来。
我的功能:
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()
};
}
}
我的 local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": "",
"AzureWebJobsServiceBus": "Endpoint=sb://<namespace>/;SharedAccessKeyName=<keyname>;SharedAccessKey=<key>",
"AzureWebJobsDocumentDBConnectionString": "mongodb://..."
}
}
但是我每次都会遇到同样的错误:
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.
我该如何解决这个问题?
【问题讨论】:
-
看起来您正在使用 Mongo 连接字符串。我不确定 Azure 功能是否支持此功能
-
您可能需要如下更改属性。此示例用于在添加新文档时读取 [FunctionName("FunctionName")] publicstaticasync Task Run( [CosmosDBTrigger("dbname", "collection", ConnectionStringSetting = "Cosmos")] IReadOnlyList
changeList, TraceWriter log)你当然还需要这个 NuGet 包:Microsoft.Azure.WebJobs.Extensions.DocumentDB 更多更新在下面的链接docs.microsoft.com/en-us/azure/azure-functions/… -
@Baskar
CosmosDBTrigger属性在我想触发函数以响应数据库更改时必须使用。我想做相反的事情:我想将函数绑定到 CosmosDB,以便我可以在将新文档分配给outputDoc变量的函数中修改数据库
标签: azure azure-cosmosdb azure-functions