gpt4 book ai didi

mongodb - MongoExpress显示 “Cannot read property ' listDatabases的“未定义”错误

转载 作者:行者123 更新时间:2023-12-02 19:20:35 24 4
gpt4 key购买 nike

我尝试使用 docker-compose.yml 创建Mongo和Mongo-Express服务器。这是我的环境

version: "3"
services:
mongo:
image: "mongo:3-stretch"
environment:
- MONGO_INITDB_ROOT_USERNAME=devroot
- MONGO_INITDB_ROOT_PASSWORD=devroot
- MONGO_INITDB_DATABASE=DataBank
ports:
- "27017:27017"
mongo-express:
image: "mongo-express:latest"
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
- ME_CONFIG_MONGODB_AUTH_USERNAME=devroot
- ME_CONFIG_MONGODB_AUTH_PASSWORD=devroot
- ME_CONFIG_OPTIONS_EDITORTHEME=ambiance
- ME_CONFIG_BASICAUTH_USERNAME=dev
- ME_CONFIG_BASICAUTH_PASSWORD=dev
depends_on:
- mongo
ports:
- "8081:8081"

结果(这里有错误):
mongo-express_1  | Thu Feb  6 03:11:36 UTC 2020 retrying to connect to mongo:27017 (3/5)
mongo-express_1 | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1 | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused

尽管出现第一个错误,但我仍然能够访问 http://localhost:8081/,但是成功登录后,它会显示(另一个错误):
mongo-express_1  | Database connected
mongo-express_1 | Connecting to admin...
mongo_1 | 2020-02-06T03:11:39.826+0000 I ACCESS [conn2] Successfully authenticated as principal devroot on admin
mongo-express_1 | Database admin connected
mongo-express_1 | Admin database is not accessible
mongo-express_1 | TypeError: Cannot read property 'listDatabases' of undefined
mongo-express_1 | at Object.connectionData.updateDatabases (/node_modules/mongo-express/lib/db.js:41:11)
mongo-express_1 | at /node_modules/mongo-express/lib/router.js:94:11
mongo-express_1 | at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)
mongo-express_1 | at next (/node_modules/express/lib/router/route.js:137:13)
mongo-express_1 | at Route.dispatch (/node_modules/express/lib/router/route.js:112:3)
mongo-express_1 | at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)
mongo-express_1 | at /node_modules/express/lib/router/index.js:281:22
mongo-express_1 | at param (/node_modules/express/lib/router/index.js:354:14)
mongo-express_1 | at param (/node_modules/express/lib/router/index.js:365:14)
mongo-express_1 | at Function.process_params (/node_modules/express/lib/router/index.js:410:3)
mongo-express_1 | GET / 500 12.737 ms - 1049

我应该看什么?

最佳答案

这里的问题是mongo-express无法访问管理数据库。将这些环境变量添加到mongo express应该可以解决您的问题

- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_ROOT_PASSWORD}

我的最终docker-compose文件看起来像这样,对我有用
version: '3.3' # specify docker-compose version

services:
mongo:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=project

mongo-express:
image: mongo-express
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_MONGODB_AUTH_DATABASE=admin
- ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
depends_on:
- mongo


注意:请不要在生产中使用它。

引用:
https://hub.docker.com/_/mongo-express

关于mongodb - MongoExpress显示 “Cannot read property ' listDatabases的“未定义”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60087244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com