2

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

Sam
  • 85
  • 7

1 Answers1

3

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
Sam
  • 85
  • 7
  • I am trying to run the emulator in Mac like ```docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -p 10255:10255 -m 3g --cpus=2.0 --namtest-linux-emulator -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1 -e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true -e AZURE_COSMOS_EMULATOR_MONGODB_COMPUTE_ENDPOINT=true -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator ``` to access cosmos emulator through mongo API. But it doesnt work. Any help – Meiyappan Kannappa Jan 07 '22 at 08:28
  • What connection string are you using? – Sam Jan 09 '22 at 21:41
  • Seems to be limitation with cosmos linux emulator, Mongo APIs are not supported. – Meiyappan Kannappa Jan 13 '22 at 05:06