Azure 函数的 Azure Cosmos DB 输入绑定不起作用 [英] Azure Cosmos DB input binding for an Azure Function doesn't work

查看:19
本文介绍了Azure 函数的 Azure Cosmos DB 输入绑定不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 microsoft learning 关于如何使用 CosmosDb 为 azure 函数添加输入绑定,但是在调用该函数时它会不断返回内部服务器错误(500 http 代码).

I was following a walkthrough from microsoft learning on how to add an input binding with CosmosDb for an azure function, however when calling the function it keeps returning internal server error (500 http code).

function.json中azure函数的配置是:

The configuration of the azure function from function.json is:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "Request",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "Response"
    },
    {
      "name": "bookmark",
      "direction": "in",
      "type": "cosmosDB",
      "databaseName": "func-io-learn-db",
      "collectionName": "Bookmarks",
      "connectionStringSetting": "learn_DOCUMENTDB",
      "id": "{id}",
      "partitionKey": "{id}",
      "sqlQuery": ""
    }
  ]
}

应用服务中有一个 learn_DOCUMENTDB 配置设置,它具有到 cosmos db 实例的有效连接字符串(已自动创建).

There is a learn_DOCUMENTDB configuration settings in the app service which has a valid connection string to cosmos db instance (was automatically created).

错误日志条目说:

无法将 CosmosDB 绑定到类型System.String".可能的原因: 1) 尝试绑定到 'Microsoft.Azure.Documents.Client.DocumentClient, Microsoft.Azure.DocumentDB.Core, Version=2.9.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 但用户类型程序集是 'System.String,System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e.

Can't bind CosmosDB to type 'System.String'. Possible causes: 1) Tried binding to 'Microsoft.Azure.Documents.Client.DocumentClient, Microsoft.Azure.DocumentDB.Core, Version=2.9.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but user type assembly was 'System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.

是不是我做错了什么?

推荐答案

我遇到了同样的问题,结果新 UI 生成的绑定与旧 UI 不同.

I had the same issue, turns out the new UI generates a different binding than the old one.

新用户界面:

{
  "name": "bookmark",
  "direction": "in",
  "type": "cosmosDB",
  "databaseName": "func-io-learn-db",
  "collectionName": "Bookmarks",
  "connectionStringSetting": "learn-0088a129-899f-4d18-b4db-5fa74daf1cc3_DOCUMENTDB",
  "id": "{id}",
  "partitionKey": "{id}",
  "sqlQuery": ""
}

旧用户界面:

{
  "type": "cosmosDB",
  "name": "bookmark",
  "databaseName": "func-io-learn-db",
  "collectionName": "Bookmarks",
  "connectionStringSetting": "learn-0088a129-899f-4d18-b4db-5fa74daf1cc3_DOCUMENTDB",
  "id": "{id}",
  "partitionKey": "{id}",
  "direction": "in"
}

删除

"sqlQuery": ""

绑定的一部分为我修复了它.

part from the binding fixed it for me.

您可以在应用服务概览页面点击遇到问题?点击返回经典Function App管理体验"切换回旧UI,如您所见这里.

You can switch back to the old UI by clicking the "Having issues? Click to go back to the classic Function App management experience" on the app service overview page, as you can see here.

这篇关于Azure 函数的 Azure Cosmos DB 输入绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆