这里访问DocumentDb是我function.json:从Azure的功能与动态DocumentId
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"webHookType": "genericJson",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "documentDB",
"name": "inputDocument",
"databaseName": "MyDb",
"collectionName": "MyCol",
"partitionKey": "main",
"id": "{documentId}",
"connection": "MyDocDbConnStr",
"direction": "in"
}
],
"disabled": false
}
这里是我的run.csx:
#r "Newtonsoft.Json"
using System;
using System.Net;
using Newtonsoft.Json;
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log, dynamic inputDocument)
{
return req.CreateResponse(HttpStatusCode.OK, $"doc title is {inputDocument.title}");
}
一切工作正常,如果我定义我的文档ID在config中的固定值。
但是,当我想用一个动态的文档ID和使用{documentId},我得到这个错误:
No binding parameter exists for 'documentId'.
我后数据是:
{
"documentId": "002"
}
哪有我发送DocumentId到我的Azure函数并从DocumentDb获取相关项目?
我测试了一个类似于此的代码(输入有效载荷,poco对象,...)但出现了一些错误。我会再次测试它,如果这个工作有效,现在让你。使用这个示例:https://github.com/Azure/azure-webjobs-sdk-script/blob/dev/sample/WebHook-Generic-CSharp/run.csx –
非常感谢,这工作完美。使用动态对象引发的错误,但使用POCO的工作,也添加输入参数function.json使这项工作(我认为我上次犯了一些错误,这一次仔细添加) –