【发布时间】:2017-07-21 15:17:26
【问题描述】:
根据我自己的进度进行编辑。
我正在尝试在使用新的 Visual Studio 工具编写的 Azure 函数中使用 DocumentDb,该工具允许我构建和部署 dll。我的 function.json 文件是由工具创建的,所以我认为我不能在 function.json 中创建我的绑定,我必须使用属性。
我已将 Microsoft.Azure.Webjobs.Extensions.DocumentDB 包添加到我的解决方案中。然后我有一个函数签名:
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)
在方法体中我有:
await docdbcli.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("customerdocumentversionsdb", "snapshots"), new
{
id = "edse",
customer = "expedia",
document = Converter.Serialize(jliff),
version = "sourceedited"
});
工具编译的function.json为:
{
"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"
}
我的文档没有写入数据库可能是因为绑定 about 被指定为 out。
【问题讨论】:
-
一般情况下,您不应将问题编辑为明显不同的问题...
标签: azure azure-functions azure-cosmosdb