Potrzebujesz utworzyć 2 dokumenty w kontenerze CosmosDB za pomocą Azure Function, czy można użyć tylko jednego powiązania zewnętrznego? Przypuszczałem, że alternatywą jest użycie klienta Cosmos DB.
Function.js
{
"bindings": [{
"name": "documents",
"type": "cosmosDBTrigger",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "db_DOCUMENTDB",
"databaseName": "db",
"collectionName": "container1",
"createLeaseCollectionIfNotExists": true
},
{
"name": "inputDocumentOut",
"type": "cosmosDB",
"databaseName": "db",
"collectionName": "container2",
"createIfNotExists": false,
"partitionKey": "{_partitionKey}",
"connectionStringSetting": "db_DOCUMENTDB",
"direction": "out"
}
]
}
Index.js
module.exports = async function(context, documents, inputDocumentOut) {
context.log('JavaScript cosmos-trigger function processed a request.');
if (!!documents && documents.length > 0) {
// code ...
}
return {
inputDocumentOut: [ doc1, doc2 ] // ???
}
};
0
smontoya
19 grudzień 2019, 19:10
1
Myślę, że w tym celu musisz użyć bezpośrednio wywołań SDK
– 4c74356b41
19 grudzień 2019, 19:28
1 odpowiedź
Tak, po prostu przekaż tablicę dokumentów do powiązania wyjściowego zamiast jednego:
module.exports = async function(context, documents) {
context.log('JavaScript cosmos-trigger function processed a request.');
var documentsToSave = [];
if (!!documents && documents.length > 0) {
// code ...
// maybe call documentsToSave.push({.. some document schema to save..});
}
context.bindings.inputDocumentOut = documentsToSave;
};
2
Matias Quaranta
19 grudzień 2019, 21:40
Podobne pytania
Nowe pytania
azure
Microsoft Azure to platforma jako usługa i infrastruktura jako usługa w chmurze. Użyj tego tagu w przypadku pytań dotyczących programowania dotyczących platformy Azure. Ogólną pomoc dotyczącą serwera można uzyskać pod adresem Super User lub Server Fault.