简体   繁体   中英

Connecting using MongoDB Compass to docker mongo image

I'm trying to see the contents of a collection using MongoDB Compass. I have username/password authentication set up. I can log in successfully but can't see any documents in the collection. Instead, I see the error:

An error occurred while loading navigation: command hostInfo requires authentication.

Docker Compose file

version: '3.7'

services:
mongo:
    image: mongo
    restart: always
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: pass
      
    volumes:
      - ./mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
      - ./mongo:/data/db

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_BASICAUTH_USERNAME: rmurad93
      ME_CONFIG_BASICAUTH_PASSWORD: Qwert111
      ME_CONFIG_MONGODB_PORT : 27017
      ME_CONFIG_MONGODB_ADMINUSERNAME: admin
      ME_CONFIG_MONGODB_ADMINPASSWORD: pass

init-mongo.js file

use admin
db.createUser({
user: "rmurad93",
pwd: "password",
roles: [ { role: "root", db: "admin" } ]
})

Line in terminal mongo compass

mongodb://localhost:27017/rmurad93:password

to connect to MongoCompass you should follow this pattern mongodb://USERNAME:PASSWORD@localhost:27017/DB_NAME

If you still can't connecting, try using (Fill in connection fields individually) option shown above instead of (Paste connection string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM