是否可以在带有1个outputbinding的cosmosDB中创建2个或更多文档

时间:2019-12-19 16:10:58

标签: azure azure-functions azure-cosmosdb

需要在具有Azure功能的CosmosDB容器中创建2个文档,是否可以仅使用一个外绑定?我以为替代方法是使用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 ] // ???
    }

};

1 个答案:

答案 0 :(得分:2)

是的,只需将一系列文档传递到输出绑定即可,而不是一个文档:

std::auto_ptr<ClonablePBase>