Sam
Sam

Reputation: 85

Failed to Connect to the Azure Cosmos DB Emulator running Docker using Mongo

I'm having trouble using the Azure Cosmos Emulator running in Docker. When run my app, I get the following error while trying to connect to the DB:

connection error: MongoNetworkError: failed to connect to server [localhost:10255] on first connect [Error: connect ETIMEDOUT 127.0.0.1:10255
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
  name: 'MongoNetworkError',
  [Symbol(mongoErrorContextSymbol)]: {}
}]

Setup

As per the Running on Docker instructions, I pulled the image and ran

md %LOCALAPPDATA%\CosmosDBEmulator\bind-mount

docker run --name azure-cosmosdb-emulator --memory 2GB --mount "type=bind,source=%LOCALAPPDATA%\CosmosDBEmulator\bind-mount,destination=C:\CosmosDB.Emulator\bind-mount" --interactive --tty -p 8081:8081 -p 8900:8900 -p 8901:8901 -p 8902:8902 -p 10250:10250 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -p 10255:10255 -p 10256:10256 -p 10350:10350 mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator

Config

  1. I've tried several different connection strings with no luck, the main one I'm using is:
mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true
  1. I am able to access the explorer on https://localhost:8081/_explorer/index.html so the emulator is running.

  2. I'm using mongoose in app

Upvotes: 2

Views: 2308

Answers (1)

Sam
Sam

Reputation: 85

After some frustrated head scratching, I found the solution! Based off the Docker container page for the emulator instructions, you need to run the following docker command:

docker run --name azure-cosmosdb-emulator --memory 2GB --mount "type=bind,source=%LOCALAPPDATA%\CosmosDBEmulator\bind-mount,destination=C:\CosmosDB.Emulator\bind-mount" --interactive --tty -e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true -p 8081:8081 -p 8900:8900 -p 8901:8901 -p 8902:8902 -p 10250:10250 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -p 10255:10255 -p 10256:10256 -p 10350:10350 mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator

The important change is the addition of: -e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true


Update:

I have since found this enables the 3.2 protocol, for the 3.6 protocol you will need to use: -e AZURE_COSMOS_EMULATOR_MONGODB_COMPUTE_ENDPOINT=true

More discussion is available in this github discussion, where someone also pointed out that the Gremlin & Casandra options are:

  • -e AZURE_COSMOS_EMULATOR_GREMLIN_ENDPOINT=true
  • -e AZURE_COSMOS_EMULATOR_CASSANDRA_ENDPOINT=true

Upvotes: 3

Related Questions