I need to update some docs(type1) with data from other docs(type2) when they create on CosmosDB. I decided use javascript Azure Functions and cosmosDBTrigger, server-less Azure option. I have problems with binding expressions to configure functions.json for get the doc-type1 associate with doc-type2 that trigger the Function. Any help could be great.
CosmosDB doc-type1:
{
"type": "type1"
"id": "123",
"serial" : "123",
"lastconf": []
}
CosmosDB doc-type2:
{
"type": "type2"
"id": "qwe",
"idtype1" : "123",
"conf1":1
}
function.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);
}
}