我正在尝试使用 CosmosDB 输入绑定(bind)添加一个新函数(Http 触发器)。
阅读有关 Azure Functions 版本 2 中输入绑定(bind)的手册,我发现我需要注册我的 binging 扩展 ( https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#register-binding-extensions ),并且 azure 门户应该向我显示一些注册提示 ( https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#azure-portal-development )
我很困惑,因为我在模板中没有看到 CosmosDB 输入绑定(bind)的选择,因此没有看到任何提示。所以我尝试在 function.json 中手动添加代码,如下所示:
{
"type": "cosmosDB",
"name": "inputDocument",
"databaseName": "DBName",
"collectionName": "CollectionName",
"connectionStringSetting": "CosmosDBConnect",
"direction": "in",
"Id": "myid",
"partitionKey": "mypartitionkey"
}
当我尝试打开函数 C# 代码时,我看到错误“函数错误(MyFuncName):绑定(bind)类型“cosmosDB”未注册。请确保类型正确且绑定(bind)扩展名正确已安装。”
在此页面上,我看到 Azure Functions 版本 2 支持 CosmosDB 输入绑定(bind) ( https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#supported-bindings )
最佳答案
更新
Azure CosmosDB 输入/输出绑定(bind)模板已可用,请不要忘记单击安装
。
您遇到了 Azure 门户可能计划在未来支持的内容。目前 v2 函数没有 cosmosdb 绑定(bind)选项,仅在 v1 中可用。已开通issue跟踪此功能支持。
解决方法是创建一个 Cosmos DB 触发器来安装 cosmosdb 扩展(实际上不需要创建触发器,只需使用它来获取安装提示),但我们仍然需要在 function.json 中手动编码来添加绑定(bind)。
关于azure - 无法在 Azure Functions V2 中注册 CosmosDB 绑定(bind)扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51885661/