Cosmos DB Emulator supports Mongo DB API. That means you can
use Emulator to develop Mongo DB solutions locally. To make it work; you need
to enable mongo endpoint first. If you have a custom port, you can override the
default Mongo DB port too. To do that, you need to run the Emulator with
different parameters. First, you need to start the windows command prompt and
change the current directory to Emulator's directory. Cosmos Db Emulator
default path is C:\Program Files\Azure Cosmos DB Emulator
Next, we need to use the parameter
"/EnableMongoDbEndpoint" to open the MongoDB endpoint. If you don't
specify a port, it will use the default port which is 10250. You can override
the port by using the parameter "/MongoPort". I have one more
important tip for you if you already have data in your Emulator. In my case, I
run Emulator with SQL API and I already have some data in it. If I try to run
the Emulator with different API like MongoDB, Emulator will remove all the
current data because it uses the same path to store data for MongoDB. If you
don't want to lose your data, you can use the parameter "/DataPath" to
store new data in different path.
You should be ready to connect your local Cosmos DB Emulator
with a MongoDB Client now. I will use Robo3T to connect my local Cosmos DB
Emulator's MongoDB engine. I need to setup the connection first. Easiest way to
setup the connection is; copy the MongoDB connection string from the Emulator's
QuickStart tab.
Paste it to the textbox in the bottom of Connection tab.
Then click on From SRV button to configure connection. Test the connection to
be sure that you can connect before you save it to use it later. If you are
having problems with the connections, check if you mistype any parameters when
you started the Cosmos Db Emulator. For some reason, if you mistype any parameters,
Emulator does not throw any errors and Emulator starts in SQL API mode.
If all worked fine you should be able to connect to Cosmos
DB Emulator as Mongo DB and start to use Robo3T manage data in Cosmos DB
Emulator. As you can see in the following screenshot, I have connected to Azure Cosmos DB Emulator's Mongo DB API. Robo 3T believes I connected to a regular Mongo DB.
This comment has been removed by a blog administrator.
ReplyDelete