-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
I'm using MongoDB 3.0.2 and I need to have it working with authentication.
With no authentication everything works just fine.
When I start the daemon with the --auth flag though, I get the following error:
|-- lucke84@Lucas-MacBook-Pro|19:15:20 :) ~/projects/innovative/my_project (user_pwd_for_mongodb) --| rails s => Booting WEBrick => Rails 4.1.9 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) => Ctrl-C to shutdown server Exiting /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/operation/read.rb:50:in `block in execute': The operation: #<Moped::Protocol::Command (Moped::Errors::OperationFailure) @length=129 @request_id=4 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="my_database.$cmd" @skip=0 @limit=-1 @selector={:distinct=>"users", :key=>"type", :query=>{}} @fields=nil> failed with error 13: "not authorized on my_database to execute command { distinct: \"users\", key: \"type\", query: {} }" See https://github.com/mongodb/mongo/blob/master/docs/errors.md for details about this error. from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:594:in `[]' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:594:in `block (2 levels) in flush' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:593:in `map' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:593:in `block in flush' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:617:in `block in logging' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/notifications.rb:159:in `block in instrument' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/notifications.rb:159:in `instrument' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/instrumentable.rb:31:in `instrument' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:616:in `logging' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:587:in `flush' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:391:in `process' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-mini-profiler-0.9.3/lib/patches/db/moped.rb:5:in `process' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/operation/read.rb:48:in `execute' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:648:in `read' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:90:in `command' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/database.rb:73:in `block in command' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/cluster.rb:249:in `block in with_primary' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:204:in `block in ensure_primary' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/executable.rb:25:in `execute' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/node.rb:203:in `ensure_primary' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/cluster.rb:248:in `with_primary' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/read_preference/primary.rb:55:in `block in with_node' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/read_preference/selectable.rb:65:in `call' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/read_preference/selectable.rb:65:in `with_retry' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/read_preference/primary.rb:54:in `with_node' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/database.rb:72:in `command' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/moped-2.0.4/lib/moped/query.rb:56:in `distinct' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/mongoid-4.0.0/lib/mongoid/contextual/mongo.rb:106:in `distinct' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/mongoid-4.0.0/lib/mongoid/contextual.rb:20:in `distinct' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/mongoid-4.0.0/lib/mongoid/findable.rb:15:in `distinct' from /Users/lucke84/projects/innovative/my_project/config/initializers/bid_manager_config.rb:49:in `block in <top (required)>' from /Users/lucke84/projects/innovative/my_project/config/initializers/bid_manager_config.rb:62:in `call' from /Users/lucke84/projects/innovative/my_project/config/initializers/bid_manager_config.rb:62:in `<top (required)>' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in `load' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in `block in load' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:232:in `load_dependency' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in `load' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/engine.rb:648:in `block in load_config_initializer' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/notifications.rb:161:in `instrument' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/engine.rb:647:in `load_config_initializer' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/engine.rb:611:in `each' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/engine.rb:611:in `block in <class:Engine>' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/initializable.rb:30:in `instance_exec' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/initializable.rb:30:in `run' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/initializable.rb:55:in `block in run_initializers' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/initializable.rb:44:in `each' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/initializable.rb:44:in `tsort_each_child' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in `call' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `call' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each' from /Users/lucke84/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/initializable.rb:54:in `run_initializers' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/application.rb:300:in `initialize!' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/railtie.rb:194:in `public_send' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/railtie.rb:194:in `method_missing' from /Users/lucke84/projects/innovative/my_project/config/environment.rb:5:in `<top (required)>' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `require' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `block in require' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:232:in `load_dependency' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `require' from /Users/lucke84/projects/innovative/my_project/config.ru:3:in `block in <main>' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize' from /Users/lucke84/projects/innovative/my_project/config.ru:in `new' from /Users/lucke84/projects/innovative/my_project/config.ru:in `<main>' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/server.rb:199:in `app' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/server.rb:50:in `app' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/server.rb:130:in `log_to_stdout' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/server.rb:67:in `start' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:81:in `block in server' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:76:in `tap' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:76:in `server' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands/commands_tasks.rb:40:in `run_command!' from /Users/lucke84/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>'
The config file is set up (imho) correctly:
development: sessions: default: database: my_database username: my_user password: my_password # Provides the hosts the default session can connect to. Must be an array # of host:port pairs. (required) hosts: - 127.0.0.1:27017 options: # ...
And I have a user & pwd set up, which I can check by connecting to the database via the console:
|-- lucke84@Lucas-MacBook-Pro|19:22:19 :( ~/projects/innovative/my_project (user_pwd_for_mongodb) --| mongo 127.0.0.1:27017/my_database -u my_user -p MongoDB shell version: 3.0.2 Enter password: connecting to: 127.0.0.1:27017/my_database >
I think the issue might be related to the authentication schema version, due to this (from mongodb.log):
2015-04-20T19:01:16.397+0200 I NETWORK [initandlisten] waiting for connections on port 27017 2015-04-20T19:01:28.619+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:49887 MONGOID-4 (1 connection now open) 2015-04-20T19:01:28.624+0200 I ACCESS [conn1] authenticate db: my_database { authenticate: 1, user: "my_user", nonce: "xxx", key: "xxx" } 2015-04-20T19:01:28.625+0200 I ACCESS [conn1] Failed to authenticate my_user@my_database with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document 2015-04-20T19:01:28.626+0200 I ACCESS [conn1] Unauthorized not authorized on my_database to execute command { distinct: "users", key: "type", query: {} } 2015-04-20T19:01:28.645+0200 I NETWORK [conn1] end connection 127.0.0.1:49887 (0 connections now open)
Is my guess right? If so, should we expect Mongoid 4 to support this new schema version any time soon or is it going to end up in Mongoid 5? If not, thoughts?
Thanks in advance,
Luca