In this article, we will see how to create an Azure Data Factory and we will copy data from Blob Storage to Cosmos DB using ADF pipelines. We will create the Source and Destination (Sink) datasets in the pipeline and will link these datasets with the Azure subscription. We will publish this pipeline and later, trigger it manually.
Prerequisites
- Azure Blob Storage Account
- Cosmos DB Account
Azure Data Factory will be created shortly.
Step 2 - Store Data in Blob Storage
Go to Storage Account and click “Storage Explorer” (Currently, it is in the preview mode).
Step 3 - Create a new Database and Collection in Azure Cosmos DB Account
Open Cosmos DB account and click Data Explorer.


Step 4 - Create a Pipeline in Azure Data Factory
We have already created Azure Data Factory. We can create a “Copy Data” pipeline now. Please open Azure Data Factory and click “Author and Monitor” button
In the Source tab, you can select the source dataset. Please click “New” Button. It will list all the data sources available in ADF. Currently, Microsoft supports more than 70 data sources.
You can ignore the file name. It will automatically pick the file from the container.
In our CSV, the first row contains the column name. Select “Column name in first row” option.
You can click the pipeline and choose the Sink tab. It is for Destination dataset.
Please click the “New” button to choose Destination dataset and select Cosmos DB as destination data source and click “Finish” button.

It will take some time to publish all the changes.
After a successful publish, we can Trigger the pipeline.
Click “Trigger” Button and choose “Trigger Now” It will open a window and choose “Finish” button.
You can download the ARM (Azure Resource Manager) template for this ADF for future use. ARM template contains the pipeline and dataset details.
Normally there are two ARM templates available for each ADF.
- {
- "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
- "contentVersion": "1.0.0.0",
- "parameters": {
- "factoryName": {
- "type": "string",
- "metadata": "Data Factory Name",
- "defaultValue": "sarathadf1"
- },
- "AzureBlobStorage1_connectionString": {
- "type": "secureString",
- "metadata": "Secure string for 'connectionString' of 'AzureBlobStorage1'"
- },
- "CosmosDb1_connectionString": {
- "type": "secureString",
- "metadata": "Secure string for 'connectionString' of 'CosmosDb1'"
- },
- "AzureBlob1_properties_typeProperties_folderPath": {
- "type": "string",
- "defaultValue": "sarathcontainer"
- }
- },
- "variables": {
- "factoryId": "[concat('Microsoft.DataFactory/factories/', parameters('factoryName'))]"
- },
- "resources": [
- {
- "name": "[concat(parameters('factoryName'), '/AzureBlobStorage1')]",
- "type": "Microsoft.DataFactory/factories/linkedServices",
- "apiVersion": "2018-06-01",
- "properties": {
- "annotations": [],
- "type": "AzureBlobStorage",
- "typeProperties": {
- "connectionString": "[parameters('AzureBlobStorage1_connectionString')]"
- }
- },
- "dependsOn": []
- },
- {
- "name": "[concat(parameters('factoryName'), '/pipeline1')]",
- "type": "Microsoft.DataFactory/factories/pipelines",
- "apiVersion": "2018-06-01",
- "properties": {
- "activities": [
- {
- "name": "BlobCopyToCosmosDB",
- "description": "Copy data from Blob Storage to Cosmos DB Account.",
- "type": "Copy",
- "dependsOn": [],
- "policy": {
- "timeout": "7.00:00:00",
- "retry": 0,
- "retryIntervalInSeconds": 30,
- "secureOutput": false,
- "secureInput": false
- },
- "userProperties": [],
- "typeProperties": {
- "source": {
- "type": "BlobSource",
- "recursive": true
- },
- "sink": {
- "type": "DocumentDbCollectionSink",
- "nestingSeparator": ".",
- "writeBatchSize": 10000,
- "writeBehavior": "insert"
- },
- "enableStaging": false,
- "dataIntegrationUnits": 0
- },
- "inputs": [
- {
- "referenceName": "AzureBlob1",
- "type": "DatasetReference",
- "parameters": {}
- }
- ],
- "outputs": [
- {
- "referenceName": "DocumentDbCollection1",
- "type": "DatasetReference",
- "parameters": {}
- }
- ]
- }
- ],
- "annotations": []
- },
- "dependsOn": [
- "[concat(variables('factoryId'), '/datasets/AzureBlob1')]",
- "[concat(variables('factoryId'), '/datasets/DocumentDbCollection1')]"
- ]
- },
- {
- "name": "[concat(parameters('factoryName'), '/AzureBlob1')]",
- "type": "Microsoft.DataFactory/factories/datasets",
- "apiVersion": "2018-06-01",
- "properties": {
- "linkedServiceName": {
- "referenceName": "AzureBlobStorage1",
- "type": "LinkedServiceReference"
- },
- "annotations": [],
- "type": "AzureBlob",
- "typeProperties": {
- "format": {
- "type": "TextFormat",
- "columnDelimiter": ",",
- "nullValue": "\\N",
- "treatEmptyAsNull": true,
- "skipLineCount": 0,
- "firstRowAsHeader": true
- },
- "folderPath": "[parameters('AzureBlob1_properties_typeProperties_folderPath')]"
- }
- },
- "dependsOn": [
- "[concat(variables('factoryId'), '/linkedServices/AzureBlobStorage1')]"
- ]
- },
- {
- "name": "[concat(parameters('factoryName'), '/DocumentDbCollection1')]",
- "type": "Microsoft.DataFactory/factories/datasets",
- "apiVersion": "2018-06-01",
- "properties": {
- "linkedServiceName": {
- "referenceName": "CosmosDb1",
- "type": "LinkedServiceReference"
- },
- "annotations": [],
- "type": "DocumentDbCollection",
- "typeProperties": {
- "collectionName": "employee"
- }
- },
- "dependsOn": [
- "[concat(variables('factoryId'), '/linkedServices/CosmosDb1')]"
- ]
- },
- {
- "name": "[concat(parameters('factoryName'), '/CosmosDb1')]",
- "type": "Microsoft.DataFactory/factories/linkedServices",
- "apiVersion": "2018-06-01",
- "properties": {
- "annotations": [],
- "type": "CosmosDb",
- "typeProperties": {
- "connectionString": "[parameters('CosmosDb1_connectionString')]"
- }
- },
- "dependsOn": []
- }
- ]
- }
arm_template_parameters.json
- {
- "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
- "contentVersion": "1.0.0.0",
- "parameters": {
- "factoryName": {
- "value": "sarathadf1"
- },
- "AzureBlobStorage1_connectionString": {
- "value": ""
- },
- "CosmosDb1_connectionString": {
- "value": ""
- },
- "AzureBlob1_properties_typeProperties_folderPath": {
- "value": "sarathcontainer"
- }
- }
- }
First json file contains all the pipeline and dataset information and second json file contains the details about parameters. You can give the storage account and other connection details in this file. We can import these ARM templates in future and save the time.

Jeremy kPosted Jul 22, 2019, 8:20 AM
Hi there, I am working with a cosmos db that holds objects with nested object arrays. For example: { "id": "bleep", "Children": [ { "Name": "Pinky", "Age": "12" }, { "Name": "Dimple", "Age": "15" } ] }. Is there any way to parse this data using data factory? Upon loading it says that for Children the type is unsupported. Thanks!
Robert CharleboisPosted Jun 26, 2019, 7:30 AM
Hi, thank you for this post. How can I read line by line a CSV file that is in a blob storage and insert/update a cosmo db collection? I have no idea how to start, if you could help. Thanks!