azure - 无法使用 Mongo 连接到运行 Docker 的 Azure Cosmos DB 模拟器

标签 azure azure-cosmosdb azure-cosmosdb-mongoapi

我在使用 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%\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

配置

  1. 我尝试了几种不同的连接字符串,但没有成功,我使用的主要连接字符串是:
mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true
  • 我可以通过 https://localhost:8081/_explorer/index.html 访问资源管理器所以模拟器正在运行。

  • 我在应用程序中使用 Mongoose

  • 最佳答案

    经过一番沮丧的挠头之后,我找到了解决方案!基于Docker container page对于模拟器指令,您需要运行以下 docker 命令:

    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
    

    重要的更改是添加了:-e AZURE_COSMOS_EMULATOR_MONGODB_EN​​DPOINT=true


    更新:

    我发现这会启用 3.2 协议(protocol),对于 3.6 协议(protocol),您需要使用:-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

    关于azure - 无法使用 Mongo 连接到运行 Docker 的 Azure Cosmos DB 模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59252095/

    相关文章:

    azure - 将 Azure 应用服务日志连接到 ELK

    azure - 我可以为 cosmosdb 使用客户端构建的 session token 吗?

    c# - 带有资源 token 的 Mongo 客户端 API

    azure - 无法从代码和 RoboMongo IDE 连接到 cosmos 文档数据库

    azure - azure staging 和生产环境的主要区别是什么,特别是对于启动任务?

    azure - 当我的 linting 脚本返回错误时,如何让 Azure DevOps Pipeline 构建失败?

    Azure 媒体服务 : Can we create SAS tokens for streaming endpoints?

    c# - Azure Function CosmosDBInput Binding 不返回值

    c# - 找不到资源 Azure Cosmos DB

    nosql - 选择正确的方法使用 Azure Cosmos DB (MongoDB) 构建 Multi-Tenancy 架构