Eri*_*ric 9 ruby database ruby-on-rails mongodb mongoid
我正在尝试通过mongoid.yml进行身份验证,但我想要在admin数据库中进行身份验证.如果我尝试在数据库字段中指定admin数据库,它会将所有集合放在那里,我不希望这样.
有没有办法将我的数据库字段设置为我想要的数据库,但是指定一个单独的身份验证数据库?这是我的mongoid.yml文件
development:
sessions:
default:
database: XC_DEV
hosts:
- IP:PORT
username: user
password: password
Run Code Online (Sandbox Code Playgroud)
smi*_*day 17
问题是一年多了,但值得回答.
是的,auth_source选项指定身份验证数据库.你必须使用mongoid 5.0.0或更高版本(mongodb网站上的文档).注意mongoid默认为admin数据库.
无法为Mongoid 4配置找到这样的选项.我在实际数据库上创建了身份验证(可能有一种我不知道的方式).
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
Run Code Online (Sandbox Code Playgroud)