Mongoid授权配置不起作用

时间:2017-11-04 04:45:22

标签: ruby-on-rails passwords mongoid authorize

在轨道上使用mongoid

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
#include <cstring>

using namespace std;

int main() {

    string title;
    string col1;
    string col2;
    string val;
    int numCommas = 0;
    vector<string> stringData;
    vector<int> intData;

    cout << "Enter a title for the data:" << endl;
    getline(cin, title);
    cout << "You entered: " << title << endl << endl;

    cout << "Enter the column 1 header:" << endl;
    getline(cin, col1);
    cout << "You entered: " << col1 << endl << endl;

    cout << "Enter the column 2 header:" << endl;
    getline(cin, col2);
    cout << "You entered: " << col2 << endl << endl;

    while (1) {
        cout << "Enter a data point (-1 to stop input):" << endl;
        getline(cin, val);

        if (val == "-1") {
            break;
        }

        if (val.find(',') == -1) {
            cout << "Error: No comma in string." << endl << endl;
        }
        else {
            for (int i = 0; i < val.length(); i++) {
                if (val.at(i) == ',') {
                    numCommas++;
                    if (numCommas > 1){
                        break;
                    }
                }
            }

            if (numCommas == 1) {
                stringData.push_back(val.substr(0, val.find(',')));
                intData.push_back(stoi(val.substr(val.find(',') + 1, val.length() - 1)));
                cout << "Data string: " << val.substr(0, val.find(',')) << endl;
                cout << "Data integer: " << stoi(val.substr(val.find(',') + 1, val.length() - 1)) << endl;
            }
            else {
                cout << "Error: Too many commas in input." << endl << endl;
            }
        }
    }

    return 0;
}

我的mongoid.yml

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

Mongodb version: 3.4.10

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

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

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

我尝试了很多不同的配置,但不能让mongoid授权工作。 任何帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

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'