gpt4 book ai didi

azure - 具有二进制 Azure 函数的 DocumentDb

转载 作者:行者123 更新时间:2023-12-03 01:07:03 25 4
gpt4 key购买 nike

根据我自己的进展进行了编辑。

我正在尝试在我使用新的 Visual Studio 工具编写的 Azure 函数中使用 DocumentDb,该工具允许我构建和部署 dll。我的 function.json 文件是由工具创建的,因此我认为我无法在 function.json 中创建绑定(bind),我必须使用属性。

我已将 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"
}

我的文档没有写入数据库,可能是因为绑定(bind) about 被指定为 out。

最佳答案

您需要引用Microsoft.Azure.WebJobs.Extensions.DocumentDB NuGet包,使用命名空间

using Microsoft.Azure.WebJobs.Extensions.DocumentDB;

然后使用 DocumentDB 属性修饰函数参数。

关于azure - 具有二进制 Azure 函数的 DocumentDb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45241227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com