适用于 Azure Functions 2.x 的 Azure Cosmos DB 触发器和绑定概述Azure Cosmos DB trigger and bindings for Azure Functions 2.x overview

此系列文章介绍如何在 Azure Functions 2.x 中使用 Azure Cosmos DB 绑定。This set of articles explains how to work with Azure Cosmos DB bindings in Azure Functions 2.x. Azure Functions 支持 Azure Cosmos DB 的触发器、输入和输出绑定。Azure Functions supports trigger, input, and output bindings for Azure Cosmos DB.

操作Action 类型Type
创建或修改 Azure Cosmos DB 文档时运行函数Run a function when an Azure Cosmos DB document is created or modified 触发器Trigger
读取 Azure Cosmos DB 文档Read an Azure Cosmos DB document 输入绑定Input binding
保存对 Azure Cosmos DB 文档的更改Save changes to an Azure Cosmos DB document 输出绑定Output binding

Note

此参考适用于 Azure Functions 2.xThis reference is for Azure Functions version 2.x. 若要了解如何在 Functions 1.x 中使用这些绑定,请参阅适用于 Azure Functions 1.x 的 Azure Cosmos DB 绑定For information about how to use these bindings in Functions 1.x, see Azure Cosmos DB bindings for Azure Functions 1.x.

此绑定最初名为 DocumentDB。This binding was originally named DocumentDB. 在 Functions 2.x 版中,触发器、绑定和包均称为 Cosmos DB。In Functions version 2.x, the trigger, bindings, and package are all named Cosmos DB.

受支持的 APISupported APIs

Azure Cosmos DB 绑定只能与 SQL API 配合使用。Azure Cosmos DB bindings are only supported for use with the SQL API. 对于所有其他的 Azure Cosmos DB API,应使用适用于 API 的静态客户端通过函数来访问数据库。API 包括 Azure Cosmos DB 的 API for MongoDB 和表 API。For all other Azure Cosmos DB APIs, you should access the database from your function by using the static client for your API, including Azure Cosmos DB's API for MongoDB, and Table API.

添加到 Functions 应用Add to your Functions app

Functions 2.x 及更高版本Functions 2.x and higher

使用触发器和绑定需要引用相应的程序包。Working with the trigger and bindings requires that you reference the appropriate package. NuGet 包用于 .NET 类库,而扩展捆绑包用于其他所有应用程序类型。The NuGet package is used for .NET class libraries while the extension bundle is used for all other application types.

语言Language 添加方式...Add by... 备注Remarks
C#C# 安装 NuGet 包版本 3.xInstalling the NuGet package, version 3.x
C# 脚本、Java、JavaScript、PowerShellC# Script, Java, JavaScript, PowerShell 注册扩展捆绑包Registering the extension bundle 建议将 Azure 工具扩展用于 Visual Studio Code。The Azure Tools extension is recommended to use with Visual Studio Code.
C# 脚本(Azure 门户中仅限联机)C# Script (online-only in Azure portal) 添加绑定Adding a binding 若要更新现有绑定扩展而不必重新发布函数应用,请参阅更新扩展To update existing binding extensions without having to republish your function app, see Update your extensions.

Functions 1.xFunctions 1.x

Functions 1.x 应用会自动引用 Microsoft.Azure.WebJobs NuGet 程序包(版本 2.x)。Functions 1.x apps automatically have a reference the Microsoft.Azure.WebJobs NuGet package, version 2.x.

后续步骤Next steps