【问题标题】:Specify authentication database in mongoid.yml在 mongoid.yml 中指定认证数据库
【发布时间】:2014-12-06 17:20:07
【问题描述】:

我正在尝试通过 mongoid.yml 进行身份验证,但我想要在 admin 数据库中进行身份验证的用户。如果我尝试在数据库字段中指定管理数据库,它会将所有集合也放在那里,我不希望这样。

有没有办法将我的数据库字段设置为我想要的数据库,但指定一个单独的身份验证数据库? 这是我目前的 mongoid.yml 文件

development:
  sessions:
    default:
      database: XC_DEV
      hosts:
        - IP:PORT
      username: user
      password: password

【问题讨论】:

    标签: ruby-on-rails ruby mongodb mongoid database


    【解决方案1】:

    这个问题已经有一年多了,但值得回答。

    是的,auth_source 选项指定身份验证数据库。您必须使用 mongoid 5.0.0 或更高版本 (documentation on the mongodb website )。注意 mongoid 默认为 admin 数据库。

    找不到Mongoid 4 configuration 的此类选项。我在实际数据库上创建了身份验证(可能有一种我不知道的方式)。

    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
    

    【讨论】:

    • 这个答案应该被标记为解决方案,因为问题是使用建议的解决方案解决的
    • A link 到 Mongoid 4 文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多