Tuesday, June 23, 2020

Azure Databases extension for Visual Studio Code



     Visual Code is extremely popular product. It is a multi-platform application and you can add all types of extensions to make it work for your needs. Also, it's free! There are couple of extensions for SQL Server, you can query and manage SQL Server by using VS Code. There is an extension for Azure Cosmos DB too, but its functionality used to be limited when it comes to querying the Cosmos DB databases. It used to let you query only Gremlin API and display pretty graphs. If you don't use Gremlin API, all you could do is creating/deleting databases and containers for other APIs.



     There was an update for Azure Cosmos DB Extension for VS Code end of May 2020. With this new update, extension started to support Azure PostgreSQL. You can manage and query Azure PostgreSQL databases now. Since extension started to support different Azure Databases, its named changed to Azure Databases.

     This version support Mongo DB too, you can run Mongo commands for your Azure Cosmos DB Mongo DB API. To start querying Mongo DB, you need to create a Mongo DB Scrapbook file. Press on CTRL + Shift + P keys, then start typing Mongo, you should see the New Mongo Scrapbook


   Next, you need to select a MongoDB database to run your commands, to do that click on Connect Database and pick your Azure Subscription then select your Azure CosmosDB Mongo DB API. After that, you are ready to run MongoDB commands. Click Execute or Execute All to run the commands.


   Another great feature of this extension is, importing feature. You can import documents from JSON files into CosmosDB. To import a JSON document in to Azure Cosmos DB press CTRL + SHIFT + P and type Import, you should see the following option to start the import.


     After you pick the file, VS Code will ask you database and container information. After you pick the container, VS Code will import your selected document into the selected container. You will see the success message in the bottom right corner like the following message.


     This is a good update for this extension, and I hope one day, I will be able to query SQL API by using this extension. I would love to see Request Unit information and all query optimization information here too. Azure Cosmos DB Data Explorer is a great online tool, but I think we need an application like VS Code to query and debug our queries. SQL Server has SSMS and Azure Data Studio, I think Azure Cosmos DB should have a similar tool to make developers life easier.


2 comments: