I'm trying to authenticate through mongoid.yml, but the user I want to authenticate as is in the admin database. If I try to specify the admin database in the database field, it will put all the collections in there too and I don't want that.
Is there a way to set my database field to a database I want, but specify a separate authentication database? Heres my mongoid.yml file at the moment
development:
sessions:
default:
database: XC_DEV
hosts:
- IP:PORT
username: user
password: password
MongoDB supports x. 509 certificate authentication for client authentication and internal authentication of the members of replica sets and sharded clusters.
In MongoDB, for authentication, you must provide a username, password, and the authentication database that is associated with this username. If the authentication database differs from the database to which you want to connect, specify the authentication database with the authSource parameter in the URL.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With