我对集合 >>> 触发器和 Azure 函数 Cosmos DB 触发器感到困惑。
我上面的问题的解决方案是创建一个 Azure 函数来触发 cosmos DB。
创建资源 >>> 计算 >>> 函数应用程序。
要添加输入和输出,请转到函数应用程序中的集成选项 >>> 您创建的触发器。
Refer the link for function binding:
此函数将在单个 cosmosDB 集合中的数据更新时触发。
我们可以添加 n 个集合作为输入,一个集合作为输出。
下面是定义绑定时会自动创建的function.json文件:
{
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "cosmosdb_DOCUMENTDB",
"databaseName": "connectivityDB",
"collectionName": "tblEvent",
"createLeaseCollectionIfNotExists": true
},
{
"type": "cosmosDB",
"name": "outputDocument",
"databaseName": "connectivityDB",
"collectionName": "tblNewEvent",
"createIfNotExists": true,
"connectionStringSetting": "cosmosdb_DOCUMENTDB",
"partitionKey": "/id",
"direction": "out"
}
]
}
下面是创建的 index.js 文件:
module.exports = function(context, input) {
var documents = context.bindings.documents;
var output = [];
if(!!input && input.length > 0){
//write your code here
}
context.bindings.outputDocument = output;
context.done();
}