如何使用新的服务器发现和监控传递选项{useUnifiedTopology:true}到Docker中的MongoCli



我是docker的新手。我正在尝试在同一个docker网络中配置mongodb和mongoexpress。我创建了一个名为some network的网络。然后我用这个命令运行mongodb,在同一个网络中设置mongo,我运行命令:

docker run -d --network some-network --name some-mongo                     
-e MONGO_INITDB_ROOT_USERNAME=mongoadmin 
-e MONGO_INITDB_ROOT_PASSWORD=secret 
mongo

然而,当我运行配置mongo express的命令时,我得到了一个错误:

docker run --network some-network -e ME_CONFIG_MONGODB_SERVER=some-mongo -p 8081:8081 mongo-express
Welcome to mongo-express
------------------------

(node:7) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(node:7) UnhandledPromiseRejectionWarning: MongoError: command listDatabases requires authentication
at Connection.<anonymous> (/node_modules/mongodb/lib/core/connection/pool.js:453:61)
at Connection.emit (events.js:314:20)
at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我错过了什么吗?,如何使用新的服务器发现和监控引擎,将选项{useUnifiedTopology:true}传递到docker中的MongoClient构造函数?

我不知道问题出在哪里,但运行这些命令解决了问题

设置mongodb

docker run --network some-network -e ME_CONFIG_MONGODB_SERVER=some-mongo -e ME_CONFIG_MONGODB_ADMINUSERNAME=mongoadmin -e ME_CONFIG_MONGODB_ADMINPASSWORD=secret -p 8081:8081 mongo-express

然后mongo express:

Docker run --name mongo-express --network some-network -e ME_CONFIG_MONGODB_SERVER=some-mongo -e ME_CONFIG_MONGODB_ADMINUSERNAME=mongoadmin -e ME_CONFIG_MONGODB_ADMINPASSWORD=secret -p 8081:8081 mongo-express

最新更新