Import and Export data from Azure Cosmos DB

In my previous posts, I wrote about deploying Azure Cosmos DB and basic of azure cosmos DB SQL queryIn this post, let us see an example for importing data from Azure cosmos DB.

The Data Migration tool is an open source solution that imports data to Azure Cosmos DB from a variety of sources, including:
  • JSON files
  • MongoDB
  • SQL Server
  • CSV files
  • Azure Table storage
  • Amazon DynamoDB
  • HBase
  • Azure Cosmos DB collections

To download Azure Cosmos DB Data Migration tool , after downloading we can run

Dtui.exe: Graphical interface version of the tool
Dt.exe:  Command-line version of the tool


Import from JSON files into Azure Cosmos DB SQL API

In my previous post, I have created 

Azure cosmos DB SQL API -    Account    - azcosmosdbsqlapi
                                                  DB            -  SQLDocDB
                                                  Collection  - JsonDocs

I am going to import below JSON document into above created DB.


{
    "id": "Doc3",
    "name": "Deepak",
    "age": 30,
    "cars": [
        {
            "name": "Porsche",
            "models": [
                {
                    "no": "718 Cayman S"
                },
                {
                    "no": "911 Targa 4S"
                }
            ]
        }
    ],
    "address": {
        "state": "TN",
        "county": "India",
        "city": "Chennai"
    }
}



In the Source Information, we need to provide the folder path that contains the JSON files -> Add Folder 


We can get the connection string details by clicking on Azure cosmos DB account name -> Keys -> PRIMARY CONNECTION STRING





We need to append the database name while providing the connection string:


ConnectionString:"AccountEndpoint=;AccountKey=;Database=;


Also we need to provide the Collection name under Add - > Collections:


Provide file path for storing the Import log information's:



Summary of the import details:



Click on View command to get the command line to run from Dt.exe


After importing successfully, refresh the Azure Cosmos DB, in the documents explorer, we will find the imported document.



Reference: 

See Also: 

No comments: