c# - 绑定(bind) CosmosDB 本地函数

标签 c# azure azure-functions azure-cosmosdb

在本地运行的 Azure Functions 上绑定(bind) Azure CosmosDB。使用此功能需要任何配置吗?

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System.Collections.Generic;

namespace CDPCompare
{
    public static class CallWS
    {
        [FunctionName("TimerTriggerCSharp")]
        public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log, IEnumerable<dynamic> inputDocument)
        {
            foreach(var item in inputDocument)
            {
                log.Info(item);
            }
        }
    }
}

最佳答案

是的,您的 inputDocument 参数需要配置。

您需要使用此属性来指定 Cosmos DB 名称和集合。

[DocumentDB("%DatabaseName%", "MyCollection")] IEnumerable<dynamic> inputDocuments

要获取该属性,您需要引用文档数据库 Microsoft.Azure.WebJobs.Extensions.DocumentDB 的 NuGet 包。最后我检查了这个 NuGet 包仍处于预发布状态,因此请确保在搜索该包时包含该包。

enter image description here

关于c# - 绑定(bind) CosmosDB 本地函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45722853/

相关文章:

authentication - 等效于 IHostingEnvironment.IsDevelopment() 的函数应用程序

c# - 如何保护 Windows 8 应用程序免受盗版?

没有嵌套在父类中的 C# 私有(private)类

c# - IObservable 的无效转换,运行时异常

c# - 读/写锁定混淆

javascript - 无效的承载访问 token

performance - CPU、RAM 和 I/O 密集型代码在 Azure Functions 上运行缓慢

azure - 用于查询某个范围内的值的表存储设计

azure - 如果在最后一个触发器的最后一个事件完成之前再次触发协调器功能会发生什么?

azure - 使用 terraform 获取 Azure 函数应用程序 SLOT 默认主机 key