Site icon 峰哥分享

mongo express 1.0.0-alpha.4 无法连接 Mongodb 5.0.2的问题

Mongo express version: 1.0.0-alpha.4
Mongodb version: 5.0.2

如果使用

docker \
run \
--network \
feng-net \
--network-alias \
mongo-host \
--name \
mongodb \
-d \
-e \
MONGO_INITDB_ROOT_USERNAME='restheart' \
-e \
MONGO_INITDB_ROOT_PASSWORD='R3ste4rt!' \
mongo \
--bind_ip_all \
--auth

来启动 mongo express, 会碰到如下问题

(node:10) [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:10) 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:454:10)
    at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:623: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:10) UnhandledPromi

解决方案如下

sudo docker run \
--network feng-net \
--network-alias mongoexp-host \
-e ME_CONFIG_MONGODB_URL='mongodb://restheart:R3ste4rt!@mongo-host:27017' \
--rm \
-p 8084:8081 \
--name mongoexp \
mongo-express

Exit mobile version