【问题标题】:Mongoid authorize config does not workMongoid 授权配置不起作用
【发布时间】:2023-03-25 19:15:01
【问题描述】:

在轨道上使用 mongoid

gem 'rails', '~> 5.1.4'
gem 'mongoid', '~> 6.1.0'

Mongodb version: 3.4.10

我的 mongoid.yml

development:
  clients:
    default:
      database: xxxx_development
      hosts:
        - xxx.xx.147.208:2200
      user: 'root'
      password: "xxxxxxxx"
      auth_source: admin

用户 root 具有 root 角色。用户/密码可以使用 MongoBooster 和 mongo cli,我的意思是可以使用 db.xxx.find({})。

但在我的 rails 应用程序中,它只是抛出

MONGODB | Topology type 'unknown' initializing.
MONGODB | Server xxx.xx.147.208:2200 initializing.
MONGODB | Topology type 'unknown' changed to type 'single'.
MONGODB | Server description for xxx.xx.147.208:2200 changed from 'unknown' to 'standalone'.
MONGODB | There was a change in the members of the 'single' topology.
MONGODB | xxx.xx.147.208:2200 | xxxx_development.count | STARTED | {"count"=>"news", "query"=>{}}
MONGODB | 116.62.147.208:2200 | xxxx_development.count | FAILED | not authorized on xxxx_development to execute command { count: "news", query: {} } (13) | 0.153356s
Completed 500 Internal Server Error in 364ms

我尝试了许多不同的配置,但无法使 mongoid 授权工作。 任何帮助将不胜感激。

【问题讨论】:

    标签: ruby-on-rails passwords mongoid authorize


    【解决方案1】:
    MONGODB | Topology type 'unknown' initializing.
    MONGODB | Server xxx.xx.147.208:2200 initializing.
    MONGODB | Topology type 'unknown' changed to type 'single'.
    MONGODB | Server description for xxx.xx.147.208:2200 changed from 'unknown' to 'standalone'.
    MONGODB | There was a change in the members of the 'single' topology.
    

    这些也是我在开发环境中遇到的错误,但在任何其他环境中都没有。

    我的配置:

    • Rails 4.2.10
    • Mongoid 5.2.1
    • MongoDB 3.4.4
    • MacOS Sierra 10.12.6

    在我的情况下,这个错误不是由 mongoid 授权工作引起的,而是由随机查询引起的。 我仍在寻找真正导致此错误的原因。 另外,这是我的崩溃报告

    12:19:03 vie2.1   |  -- Control frame information -----------------------------------------------
    12:19:03 vie2.1   |  c:0005 p:---- s:0014 e:000013 CFUNC  :sleep
    12:19:03 vie2.1   |  c:0004 p:0010 s:0010 e:000009 BLOCK  /Users/7in4/.rvm/gems/ruby-2.3.1/gems/mongo-2.4.3/lib/mongo/cluster/cursor_reaper.rb:168 [FINISH]
    12:19:03 vie2.1   |  c:0003 p:---- s:0008 e:000007 CFUNC  :loop
    12:19:03 vie2.1   |  c:0002 p:0009 s:0005 e:000004 BLOCK  /Users/7in4/.rvm/gems/ruby-2.3.1/gems/mongo-2.4.3/lib/mongo/cluster/cursor_reaper.rb:167 [FINISH]
    12:19:03 vie2.1   |  c:0001 p:---- s:0002 e:000001 (none) [FINISH]
    12:19:03 vie2.1   |  -- Ruby level backtrace information ----------------------------------------
    12:19:03 vie2.1   |  /Users/7in4/.rvm/gems/ruby-2.3.1/gems/mongo-2.4.3/lib/mongo/cluster/cursor_reaper.rb:167:in `block in start!'
    12:19:03 vie2.1   |  /Users/7in4/.rvm/gems/ruby-2.3.1/gems/mongo-2.4.3/lib/mongo/cluster/cursor_reaper.rb:167:in `loop'
    12:19:03 vie2.1   |  /Users/7in4/.rvm/gems/ruby-2.3.1/gems/mongo-2.4.3/lib/mongo/cluster/cursor_reaper.rb:168:in `block (2 levels) in start!'
    12:19:03 vie2.1   |  /Users/7in4/.rvm/gems/ruby-2.3.1/gems/mongo-2.4.3/lib/mongo/cluster/cursor_reaper.rb:168:in `sleep'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-03
      • 2012-04-24
      • 2015-08-09
      • 2017-06-25
      • 2018-06-15
      • 2013-12-11
      • 2014-10-27
      相关资源
      最近更新 更多