MongoID 无效机制 mongodb_cr
MongoID InvalidMechanism mongodb_cr
当我尝试连接到远程数据库时出现以下错误
"mongodb_cr" is invalid, please use mongodb_cr, mongodb_x509, gssapi or plain.
我可以使用相同的凭据和身份验证机制从我的终端或任何其他应用程序(如 robomongo)毫无问题地进行连接
让我不解的是"mongodb_cr" is invalid
请用mongodb_cr
这是我的 mongoid.yml 文件的内容
development:
clients:
default:
database: urijijami
hosts:
- <%= ENV['MONGO_HOST'] || 'localhost' %>
options:
user: <%= ENV['MONGO_USER'] %>
password: <%= ENV['MONGO_PASS'] %>
# Change the default authentication mechanism. Valid options are: :scram,
# :mongodb_cr, :mongodb_x509, and :plain. Note that all authentication
# mechanisms require username and password, with the exception of :mongodb_x509.
# Default on mongoDB 3.0 is :scram, default on 2.4 and 2.6 is :plain.
auth_mech: mongodb_cr
# Configure Mongoid specific options. (optional)
options:
raise_not_found_error: false
根据注释掉的区域,该行应该是这样的:
auth_mech: :mongodb_cr
原来没有设置 MONGO_USER 和 MONGO_PASS,因此连接失败。我将 auth_mech 选项更改为
<%= 'auth_mech: :mongodb_cr' if ENV['MONGO_USER'].present? %>
现在它完美地工作
当我尝试连接到远程数据库时出现以下错误
"mongodb_cr" is invalid, please use mongodb_cr, mongodb_x509, gssapi or plain.
我可以使用相同的凭据和身份验证机制从我的终端或任何其他应用程序(如 robomongo)毫无问题地进行连接
让我不解的是"mongodb_cr" is invalid
请用mongodb_cr
这是我的 mongoid.yml 文件的内容
development:
clients:
default:
database: urijijami
hosts:
- <%= ENV['MONGO_HOST'] || 'localhost' %>
options:
user: <%= ENV['MONGO_USER'] %>
password: <%= ENV['MONGO_PASS'] %>
# Change the default authentication mechanism. Valid options are: :scram,
# :mongodb_cr, :mongodb_x509, and :plain. Note that all authentication
# mechanisms require username and password, with the exception of :mongodb_x509.
# Default on mongoDB 3.0 is :scram, default on 2.4 and 2.6 is :plain.
auth_mech: mongodb_cr
# Configure Mongoid specific options. (optional)
options:
raise_not_found_error: false
根据注释掉的区域,该行应该是这样的:
auth_mech: :mongodb_cr
原来没有设置 MONGO_USER 和 MONGO_PASS,因此连接失败。我将 auth_mech 选项更改为
<%= 'auth_mech: :mongodb_cr' if ENV['MONGO_USER'].present? %>
现在它完美地工作