MongoExpress显示“无法读取未定义的属性'listDatabases””。错误 [英] MongoExpress shows "Cannot read property 'listDatabases' of undefined" error

查看:184
本文介绍了MongoExpress显示“无法读取未定义的属性'listDatabases””。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to create Mongo and Mongo-Express server using docker-compose.yml. Here's my setting

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 / 但是,如果成功登录,它会显示(另一个错误):


Despite the first error, I still was able to access http://localhost:8081/ But when logged-in successfully, it shows (another error):

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



我应该看什么?


What should I look in to?

推荐答案

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

Problem here is that mongo-express is not able to access the admin database. Adding these environment variables to mongo express should fix your problem

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

我的最终docker-compose文件如下所示

My final docker-compose file looks like this and it works for me

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

这篇关于MongoExpress显示“无法读取未定义的属性'listDatabases””。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆