The Azure Cosmos DB is a multi-model database, which can also be used either as source or destination for an ETLBox data flow. This article will give you an overview how to use the connector.
In the following examples, we will use the the Pocos Movie and Person.
Also we will need some methods to create demo data:
Lastly, we need a helper method to (re)create a container and set up a container with existing data (though the latter is possible with an ETLBox dataflow, using this method improves the readability of the example codings):
By default, data is inserted as bulk without an enclosing transaction. If you prefer to insert data as part of a transactional batch, set the property UseTransactionBatch to true. The maximum allowed batch size is then 100 (due to the limitation of Cosmos Db).
This works best if all data has the same partition key. If the incoming data has different partition keys, the data is inserted in multiple batches, grouped by each partition key.
Make sure to add a partition key for each record using the action.
If any of the records in the batch is flawed, the whole batch will not be inserted.
You can redirect erroneous batches using ‘LinkErrorsTo()’ when linking your components.
Setting this property to true will decrease performance.
Instead of passing a connection string, the CosmosDbSource and CosmosDbDestination also offer different properties to pass credentials:
AzureKeyCredential: Optional: An Azure Key Credential used when opening the connection (works only in combination with ConnectionString
AzureTokenCredential: Optional: An Azure Token Credential used when opening the connection (works only in combination with ConnectionString)
AccountEndpoint: Optional: An Azure Cosmos Db account endpoint used when opening the connection (works only in combination with AuthKeyOrResourceToken). ConnectionString, AzureKeyCredential and AzureTokenCredential have no effect then.
AuthKeyOrResourceToken: Optional: An Azure Authorization key or resource token which is used when opening the connection. (works only in combination with AccountEndpoint). ConnectionString, AzureKeyCredential and AzureTokenCredential have no effect then.
Like all other data flow components, Cosmos DB source and destination support the dynamic ExpandoObject. Simple use either CosmosDbSource or CosmosDbSource<ExpandoObject> instead of CosmosDbSource<T>.