LoginSignup
0
0

More than 3 years have passed since last update.

Docker(Docker Compose)で立ち上げたMongoDBにプログラムから接続すると認証エラーになる件の解決

Last updated at Posted at 2019-07-04

authSource=adminが必要。

# Ruby
client = Mongo::Client.new('mongodb://root:example@mongo:27017/mydb?authSource=admin')

なお、docker-compose.ymlはこんな感じで書いてある想定。

# Use root/example as user/password credentials
version: '3.1'

services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0