ruby on rails - Not able to connect to mongodb using mongoid -


if try connecting using mongo driver rails console, works fine:

client = mongo::client.new('mongodb://username:password@dds-xxxxxxxx.mongodb.singapore.rds.aliyuncs.com:3717,dds-xxxxxxxx.mongodb.singapore.rds.aliyuncs.com:3717/graspire?replicaset=mgset-xxxxxxx') client.database.collection(:courses).count 

the above code works fine , gives me result. if rails console do:

course.count 

then error:

mongo::error::noserveravailable: no server available matching preference: #<mongo::serverselector::primary:0x52072480 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 , local_threshold=0.015 

this mongoid.yml

production:   # configure available database clients. (required)   clients:     # defines default client. (required)     default:       uri: mongodb://username:password@dds-xxxxxxxx.mongodb.singapore.rds.aliyuncs.com:3717,dds-xxxxxxxx.mongodb.singapore.rds.aliyuncs.com:3717/graspire?replicaset=mgset-xxxxxxx   options: 

using mongoid version- 6.1.0, mongo version - 2.4.1

how running rails console?. without specifying enviroment, rails console default runs in development. please check if development group in defined inside mongoid.yml.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -