2013-12-09 37 views
1

当mongoid访问auth启用mongo服务器时,我收到“未授权”错误。当我禁用mongo中的auth选项时,不会引发异常。使用用户名和密码从mongoid获取未经授权的错误

有人可以指出我为什么我得到这个错误?

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 
+1

我们也有问题,看起来我们并不孤单:https://github.com/mongoid/mongoid/issues/3438 – mbarthelemy

回答

相关问题