如何连接到 MongoDB 的 Azure CosmosDB 模拟器?

How do I connect to the Azure CosmosDB Emulator for MongoDB?

尝试使用 MongoDB 连接字符串 mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true 连接到 Azure CosmosDB 的本地模拟器时,我收到以下错误:

{ MongoNetworkError: failed to connect to server [localhost:10255] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:10255]
    at Pool.<anonymous> (D:\github\myapp\node_modules\mongodb-core\lib\topologies\server.js:431:11)
    at Pool.emit (events.js:189:13)
    at connect (D:\github\myapp\node_modules\mongodb-core\lib\connection\pool.js:557:14)
    at makeConnection (D:\github\myapp\node_modules\mongodb-core\lib\connection\connect.js:39:11)
    at callback (D:\github\myapp\node_modules\mongodb-core\lib\connection\connect.js:261:5)
    at TLSSocket.err (D:\github\myapp\node_modules\mongodb-core\lib\connection\connect.js:286:7)
    at Object.onceWrapper (events.js:277:13)
    at TLSSocket.emit (events.js:189:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

我已经从 Microsoft Download Center and followed the installation instructions according to the Microsoft docs

安装了最新版本的模拟器(当前为 v2.4.5)

我尝试使用 Mongoose connect 与 Node.js 进行连接(与 Azure 云配置完美配合),并使用 VS Code Azure CosmosDB 扩展。两者都会产生相同的错误。

连接本地模拟器的正确方法是什么?

原来我需要从命令行 运行 模拟器并启用 mongodb 端点。不需要单独运行MongoDB

以下对我有用:

cd "C:\Program Files\Azure Cosmos DB Emulator"

然后

.\CosmosDB.Emulator.exe /EnableMongoDbEndpoint

在 运行 执行这些命令后,我能够使用 Azure 模拟器为 MongoDB 提供的连接字符串并成功连接并 read/write 到本地数据库。