azure - 具有 CosmosDB 输入的时间触发功能
问题描述
我在 azure 函数中创建了一个时间触发函数,并添加了一个 CosmosDB 输入,如下所示。
下面是 .csx 文件
#r "Microsoft.Azure.Documents.Client"
using System;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
public static async Task Run(TimerInfo myTimer, string[] inputDocument, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
// string [] = bindings.inputDocument;
DocumentClient client;
}
如何从 cosmosDb 获取输入文档到这个 csx 文件中?
我对 C# 不熟悉,在 javascript 中我们将使用var Data = context.bindings.DataInput;
How to do the same in c#?
解决方案
您可以像下面的代码片段一样使用它
public static void Run(TimerInfo myTimer, IEnumerable<dynamic> documents)
{
foreach (var doc in documents)
{
// operate on each document
}
}
文档中的更多示例
评论中的问题
如果我们有多个 cosmos Db 输入,是否需要添加如下?
即使您有多个输入,IEnumerable<dynamic> documents
也不会使用。你可以迭代列表。
如果我们有 cosmosDB 输出,如何添加?
在 this 中使用的out object
是指向您的绑定。
public static void Run(string myQueueItem, out object employeeDocument, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
dynamic employee = JObject.Parse(myQueueItem);
employeeDocument = new {
id = employee.name + "-" + employee.employeeId,
name = employee.name,
employeeId = employee.employeeId,
address = employee.address
};
}
有关输出的更多信息
推荐阅读
- pattern-matching - 使用 python POO 进行图挖掘:创建图并测试匹配
- node.js - 在电子反应应用程序中导入 whatsapp-web.js nodejs 模块的问题
- windows - 我可以获得适用于 Windows 32 位的 MongoDB Shell 吗?
- linux - 未设置带有 PKG_CHECK_MODULES 的 Autoconf
_CFLAGS 和 _LIBS 变量 - regex - 正则表达式在 \n 和 \t 之间选择字符,中间有数字
- java - Android 导航组件 - 如果用户未登录,则导航到其他活动
- graphql - 在 Graphql (NestJs) 中扩展泛型类型
- javascript - 其他js文件上的异步函数总是返回未定义,但函数运行
- docker - 无法 cd 进入 Docker 卷中目录的软链接
- javascript - Heroku - 未找到