Rails连接远程mongo数据库报错:
"Could not connect to a primary node for replica set #<Moped::Cluster:27191916 @seeds=[<Moped::Node resolved_address=nil>]>"
配置文件内容如下:
development: sessions: default: database: spider hosts: - db.***.com:10001 options: options: test: sessions: default: database: spider_admin_test hosts: - localhost:27017 options: read: primary max_retries: 1 retry_interval: 0
上stackoverflow.com找解决方案
原文地址:http://stackoverflow.com/questions/21128597/mongoid-with-rails-4-could-not-connect-to-a-primary-node-resolved-address
大致是说把域名的形式改成IP形式,于是我尝试将域名改成具体IP后,程序恢复正常,修改后如下:
development: sessions: default: database: spider hosts: - 0.0.0.0:10001 # 需更换成你的程序所使用的mongo服务器具体IP地址 options: options: test: sessions: default: database: spider_admin_test hosts: - localhost:27017 options: read: primary max_retries: 1 retry_interval: 0
时间: 2024-10-11 04:19:26