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
我們也有問題,看起來我們並不孤單:https://github.com/mongoid/mongoid/issues/3438 – mbarthelemy