Specify authentication database in mongoid.yml Specify authentication database in mongoid.yml database database

Specify authentication database in mongoid.yml


The question is over a year old but it deserves an answer.

Yes, the auth_source option specifies the authentication database. You got to be on mongoid 5.0.0 or higher (documentation on the mongodb website ). Note mongoid defaults to the the admin database.

Can't find such an option for the Mongoid 4 configuration. I created authentications on the actual databases (there could be a way I am not aware of).

Segment of mongoid.yml (5.0.0):

development:  clients:    default:      database: database_name      hosts:        - localhost:27017      options:        # The name of the user for authentication.        user: "<%= Rails.application.secrets.mongoid['user'] %>"        # The password of the user for authentication.        password: "<%= Rails.application.secrets.mongoid['password'] %>"        # The user's database roles.        roles:          - 'dbOwner'        # Change the default authentication mechanism. Valid options are: :scram,        # :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default        # on 2.4 and 2.6 is :plain)        # auth_mech: :scram        # The database or source to authenticate the user against. (default: admin)        auth_source: admin