Azure Cosmos DB extension for Visual Studio Code gives Azure developers set of powerful commands to working with Cosmos DB. With the help of Azure Cosmos DB extension, from Visual Studio Code, you can easily create and delete databases, collections, and view, modify and delete documents. With the help of this extension, you can connect with Cosmos DB very easily and manage the entities like adding or deleting collections and databases. The overall hierarchical representation gives a straightforward way to understand the overall structure of your Cosmos DB.
To start with, first, you must install the extension from the marketplace. To do that, search for Azure Cosmos DB extension in the marketplace and Click on Install.
After installation of the extension, you will find Azure Cosmos DB section of Explore section of Visual Studio Code.
If you want to take a quick look at all the different types of commands for Azure Cosmos DB, open the Show All Command plate and search for Cosmos. This will give you quick glance at different features.
Move back to Azure Cosmos DB Extension section in the Explorer panel. From there you can sign in to Azure Account to view your Cosmos DB Accounts inside Visual Studio Code or select “Attach Database Account” to attach any database. When you select “Attach Database Account”, VS Code will show you the list of Database Account API – and you need to select specific to your database.
Once you select the specific Database Account API, Visual Studio Code will ask for the Connection String.
You can obtain the connection string from the Azure Portal, Navigate to the respective Cosmos DB Resource, and from the left side panel Settings – Connection String Copy the Primary Connection String.
Past the connection string and press Enter. Visual Studio Code now loads and attach the selected Cosmos DB.
Now you can Add, Modify Database, collection, and documents within Visual Studio Code. Play around with all the commands and features of the extension.
Visual Studio Code & Azure Cosmos DB Emulator
The Azure Cosmos DB Emulator provides a local environment that emulates the Azure Cosmos DB service for your development. Using the Azure Cosmos DB Emulator, you can develop and test your application locally, without creating an Azure subscription. From Visual Studio Code, using the Azure Cosmos DB Extension, you can connect with Local Emulator as well.
First, start the local Azure Cosmos DB Emulator, and make sure it’s running (You can check this from system tray ) and verify the access by exploring the local emulator (https://localhost:<running port>/_explorer/index.html )
Once you verify your Azure Cosmos DB Emulator is running, you can go back to Visual Studio Code and try to attach the emulator by selecting Connected with Azure Cosmos DB Emulator” option
Wait for a while, you will find your local Cosmos DB data also mapped in Visual Studio Code
That’s it. This extension is very powerful and if you are developing Azure based solution with Visual Studio code, you must start exploring this.
Hope this helps.
Pingback: Dew Drop - February 9, 2018 (#2662) - Morning Dew
Pingback: Azure Weekly: Feb 12, 2018 – Build Azure