【问题标题】:Getting unauthorised error from mongoid with username and password使用用户名和密码从 mongoid 获取未经授权的错误
【发布时间】:2013-12-09 02:16:47
【问题描述】:

当访问 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

【问题讨论】:

标签: ruby-on-rails mongodb ruby-on-rails-4 mongoid


【解决方案1】:

这是 mongoid 所依赖的 moped gem 中的一个错误。 https://github.com/mongoid/moped/issues/243

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    相关资源
    最近更新 更多