无法使用Mongo连接到运行Docker的Azure Cosmos DB仿真程序 [英] Failed to Connect to the Azure Cosmos DB Emulator running Docker using Mongo

查看:58
本文介绍了无法使用Mongo连接到运行Docker的Azure Cosmos DB仿真程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用在Docker中运行的Azure Cosmos模拟器时遇到问题。运行我的应用程序时,尝试连接到数据库时出现以下错误:

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)]: {}
}]

安装

根据Running on Docker instructions,我拉出图像并运行

md %LOCALAPPDATA%CosmosDBEmulatorind-mount

docker run --name azure-cosmosdb-emulator --memory 2GB --mount "type=bind,source=%LOCALAPPDATA%CosmosDBEmulatorind-mount,destination=C:CosmosDB.Emulatorind-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

配置

  1. 我尝试了几种不同的连接字符串,但都没有成功,我正在使用的主要连接字符串是:
mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true
  1. 我能够在https://localhost:8081/_explorer/index.html访问资源管理器,因此仿真程序正在运行。

  2. 我在APP中使用Mongoose

推荐答案

在一阵沮丧的挠头之后,我找到了解决办法!根据仿真器指令的Docker container page,您需要运行以下docker命令:

docker run --name azure-cosmosdb-emulator --memory 2GB --mount "type=bind,source=%LOCALAPPDATA%CosmosDBEmulatorind-mount,destination=C:CosmosDB.Emulatorind-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

重要的更改是增加了:-e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true


更新:

我发现这会启用3.2协议,对于您需要使用的3.6协议:-e AZURE_COSMOS_EMULATOR_MONGODB_COMPUTE_ENDPOINT=true

github discussion中有更多讨论,有人还指出Gremlin&;Casandra选项为:

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

这篇关于无法使用Mongo连接到运行Docker的Azure Cosmos DB仿真程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆