Wondering what to do if you do not have an Azure subscription? Well, Azure Cosmos DB can be used to write and test applications locally using the Cosmos database. And to do that, we do not need to have an Azure subscription at all. We can simply download the local emulator for Cosmos DB and test our applications inside the system without the need of an Internet connection, the only downside being that we won’t be able to work with the feature of global distribution using the emulator.
To work with emulator, we just need two things:
- Master key
- Connection string of the emulator
The key can be found on the documentation on the Azure Cosmos DB emulator and the connection string plays an important role when it comes to connecting with the real Cosmos DB account. When we want to deploy our code on to the real account, we can simply change the connection string of the emulator to that of the real Cosmos DB account, and there we go!
Steps to install the local emulator:
- Download the local emulator from the browser and install it. You should get a screen like this. You can simply search to download the emulator on Google.
- Once it is installed, you’ll get the access to the portal and then comes the master key requirement which can be found in the Documentation link given within the emulator.
- Grab your master key, and you can then play around with the Cosmos DB emulator which is no less than a real Cosmos DB account.
Now let us try to understand the first screen that we get when we start the Emulator.
So here is the quick start page where the first option is URI, which is the identifier for your emulator link. If you see in the address of the browser, it is the same link as URI.
Next is the Primary key which is the unique identification of your account and this is what maps and saves what you do in your emulator from creating collections to working with documents. Well, we will come to that later.
Then comes the connection string which is going to help you deploy our project on to the real Cosmos DB account. This is Emulator connection string which will be then replaced by the Cosmos DB account connection string. Also, we have a separate connection string for MongoDB API users since MongoDB API support is like a wire level support for those who are already working with MongoDB and this string will help them deploy their project and work around with the Cosmos DB functionalities.
On the left side panel, if you see the next option is the Explorer, where we can create the collections and documents. Since the word collections is coming a lot into use, let us understand it as a container for all the huge data that we will use on Cosmos DB, for now. Now this container has different names for different APIs, like the SQL API calls it collection, whereas the Gremlin API will call it Graphs and so on.
The explorer tab look like this:
On the top left is the option to create a new collection that will be the container for your data.
In the next blog post, we will go into the details of how to start working with Cosmos DB creating collections, documents etc.