i'm able connect mongodb , able run below commands
mongo -host hostname:port db.getsiblingdb("$external").auth({ mechanism: "plain", user: "<username>", pwd: "<password>", digestpassword: false }) use dbname db.collectionanme.find({query here}) the same commands tried ruby i'm getting error message >> not authorized query on dbname.collectionname (13)
below ruby code:
require 'mongo' include mongo client = mongo::client.new(['localhost:port']) client.with(:auth_mech => :plain, :user => '<user>', :password => '<password>', :digestpassword => false) db = client.use('dbname') db[:collectionname].find(query here).each |doc| puts doc end here's error
c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/operation/result.rb:214:in `validate!': not authorized query on dbname.collectionname (13) (mongo::error::operationfailure) c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/operation/read/query.rb:62:in `block in execute_message' c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/server/connection_pool.rb:99:in `with_connection' c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/server/context.rb:63:in `with_connection' c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/operation/read/query.rb:61:in `execute_message' c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/operation/read/query.rb:55:in `execute' c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/collection/view.rb:164:in `send_initial_query' c:/ruby200/lib/ruby/gems/2.0.0/gems/mongo-2.0.6/lib/mongo/collection/view/iterable.rb:39:in `each'
i not able complete work due access issues. code looks below
require 'mongo' include mongo mongo::client.new(['hostname:port'], :auth_mech => :plain, :auth_source => :external, :user => 'username', :password => 'password', :digestpassword => false).use('db_name')['collection_name'].find("query").to_a
Comments
Post a Comment