我正在使用Mongo 3.4 当我登录到管理数据库时,我可以看到我的用户:
> show users
{
"_id" : "admin.jon",
"user" : "jon",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
{
"_id" : "admin.bill",
"user" : "bill",
"db" : "admin",
"roles" : [
{
"role" : "readWrite",
"db" : "leads"
},
{
"role" : "dbOwner",
"db" : "leads"
}
]
}
通知帐单是“潜在客户”数据库的所有者,应该具有readWrite访问权限。
但是,当通过生产服务器上的rails c使用Mongo Ruby驱动程序时,我尝试列出集合,但出现错误:
client = Mongo::Client.new([Rails.application.secrets.mongo], user: 'bill', password: 'xxxxxx', database: "leads")
db = client.database
db.collections
# => Mongo::Auth::Unauthorized (User bill (mechanism: scram) is not authorized to access leads (auth source: leads) (used mechanism: SCRAM-SHA-1): Authentication failed. (on localhost:xxxxx))
我在做什么错了?