无法连接使用mongoid
问题描述:
如果我尝试使用从铁轨控制台蒙戈驱动器连接到MongoDB的,它工作正常:无法连接使用mongoid
client = Mongo::Client.new('mongodb://username:[email protected]:3717,dds-xxxxxxxx.mongodb.singapore.rds.aliyuncs.com:3717/graspire?replicaSet=mgset-xxxxxxx')
client.database.collection(:courses).count
上面的代码工作正常,并给我的结果。但是,如果从铁轨控制台我做的:
Course.count
然后我得到这个错误:
Mongo::Error::NoServerAvailable: No server is available matching preference: #<Mongo::ServerSelector::Primary:0x52072480 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015
这是我mongoid.yml
production:
# Configure available database clients. (required)
clients:
# Defines the default client. (required)
default:
uri: mongodb://username:[email protected]:3717,dds-xxxxxxxx.mongodb.singapore.rds.aliyuncs.com:3717/graspire?replicaSet=mgset-xxxxxxx
options:
使用mongoid版本 - 6.1.0, mongo版本 - 2.4.1
哪个mongoid版本? – meshin
mongoid version- 6.1.0,mongo version - 2.4.1 – vigenere