当访问auth启用的mongo服务器时,我从mongoid收到“未授权”错误。当我在mongo中禁用auth选项时,不会引发异常。
有人能指出我为什么会收到这个错误吗?
irb(main):010:0> Test.count
MOPED: 10.0.0.4:27017 COMMAND database=admin command={:ismaster=>1} runtime: 1.7334ms
MOPED: 10.0.0.4:27017 COMMAND database=staging command={:count=>"tests", :query=>{}} runtime: 1.0563ms
Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
@length=91
@request_id=9
@response_to=0
@op_code=2004
@flags=[]
@full_collection_name="staging.$cmd"
@skip=0
@limit=-1
@selector={:count=>"tests", :query=>{}}
@fields=nil>
failed with error "unauthorized"
用户的权限如下所示。
> use staging
switched to db staging
> show users
{
"_id" : ObjectId("xxx"),
"pwd" : "xxx",
"roles" : [
"readWrite",
"dbAdmin"
],
"user" : "username"
}
我的mondoid.yml看起来像这样。
staging:
sessions:
default:
database: staging
username: username
password: "password"
hosts:
- 10.0.0.4:27017
使用此用户从我的控制台访问mongo时没有问题。
环境
rails 4.0.2
mongoid 4.0.0.alpha1