【问题标题】:DocumentDb with Binary Azure Function具有二进制 Azure 函数的 DocumentDb
【发布时间】: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


【解决方案1】:

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

using Microsoft.Azure.WebJobs.Extensions.DocumentDB;

然后用DocumentDB 属性装饰你的函数参数。

【讨论】:

  • 我认为当您发布答案时,谢谢。但是现在我的文档没有被写入数据库,因为 docdbcli 为空。
【解决方案2】:

原来是库 v1.5 的问题。使用 1.4 有效。

【讨论】:

    【解决方案3】:

    DocumentDb 中似乎发生了重大变化。它是在一个次要的构建版本中完成的,因此它违反了语义版本控制。 https://github.com/Azure/azure-webjobs-sdk-script/issues/1679

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      相关资源
      最近更新 更多