Connecting using MongoDB Compass to docker mongo image
Asked Answered
E

1

6

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
Embarkment answered 27/7, 2020 at 19:41 Comment(0)
A
1

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)

Airframe answered 21/9, 2020 at 3:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.