当他们在 CosmosDB 上创建时,我需要使用来自其他文档(type2)的数据更新一些文档(type1)。我决定使用 javascript Azure Functions 和 cosmosDBTrigger,无服务器 Azure 选项。我在绑定表达式以配置 functions.json 以获取与触发函数的 doc-type2 关联的 doc-type1 时遇到问题。任何帮助都可能很棒。
CosmosDB 文档类型 1:
{
"type": "type1"
"id": "123",
"serial" : "123",
"lastconf": []
}
CosmosDB 文档类型 2:
{
"type": "type2"
"id": "qwe",
"idtype1" : "123",
"conf1":1
}
函数.json
{
"bindings": [{
"name": "documents",
"type": "cosmosDBTrigger",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "_DOCUMENTDB",
"databaseName": "db",
"collectionName": "dbDev",
"createLeaseCollectionIfNotExists": true
},
{
"name": "inputDocumentIn",
"type": "cosmosDB",
"databaseName": "db",
"collectionName": "dbDev",
"id": "{idtype1}", // sqlQuery ??
"connectionStringSetting": "_DOCUMENTDB",
"direction": "in"
},
{
"name": "inputDocumentOut",
"type": "cosmosDB",
"databaseName": "db",
"collectionName": "dbDev",
"createIfNotExists": false,
"connectionStringSetting": "_DOCUMENTDB",
"direction": "out"
} ]
}
index.js:
module.exports = async function(context, documents, inputDocumentIn, inputDocumentOut) {
context.log('JavaScript trigger function processed a request.');
if (!!documents && documents.length > 0) {
context.log('Documents: ', documents);
inputDocumentOut = inputDocumentIn;
inputDocumentOut.lastconf = documents.conf1; //documents[i].conf1; ??
context.log('inputDocumentOut: ', inputDocumentOut);
}
}