即使在 mongoid.yml 中指定不同的地址后,Mongoid仍会在 27017 连接到本地主机
我正在 EC2 上运行 Rails 应用程序,并使用 mongoHQ 作为 DBMS。我在 mongoid.yml 中指定了以下值,
defaults: &defaults
host: staff.mongohq.com
port: 10082
username: CodeMaster123
password: 00000000
development:
<<: *defaults
database: app-development
test:
<<: *defaults
database: app-box-test
但是当我执行 rails s
时,它会抛出一个错误,指出
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.4.0/lib/mongo/connection.rb:
526:in `connect': Failed to connect to a master node at localhost:27017(Mongo::ConnectionFailure)
是否有方法检查 mongoid 是否正在读取 mongoid.yml?
编辑:
如果我使用错误的端口号,则会显示错误
Failed to connect to a master node at spd.mongohq.com:10092 (Mongo::ConnectionFailure)
这意味着它忽略 mongoid.yml 中指定的连接选项并连接到 localhost:27017。为什么会发生这种情况?
I'm running a rails application on EC2, and I'm using mongoHQ as DBMS. I've specified following values in mongoid.yml
defaults: &defaults
host: staff.mongohq.com
port: 10082
username: CodeMaster123
password: 00000000
development:
<<: *defaults
database: app-development
test:
<<: *defaults
database: app-box-test
But when I execute rails s
it throws an error saying
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.4.0/lib/mongo/connection.rb:
526:in `connect': Failed to connect to a master node at localhost:27017(Mongo::ConnectionFailure)
Is there a way to check whether mongoid is reading mongoid.yml?
Edit:
If I use wrong port number then it show an error
Failed to connect to a master node at spd.mongohq.com:10092 (Mongo::ConnectionFailure)
It means that it ignore the the connection options specified in mongoid.yml and connects to localhost:27017. Why is it happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您能否尝试在 yaml 文件中编写完整的开发选项而不是使用指针?我相信这个部门存在错误。
Can you please try writing the full options under development: in yaml file rather then using pointers? I believe there has been bugs in this departement.
Mongoid 在其当前的公共版本(2.3.4)中似乎不支持正确的 YAML 加载。您可以查看此提交以了解更多详细信息:
将选项和环境重构到它们自己的模块中
将以下内容放入您的 Gemfile 中以从最近的代码中受益提交(对于我来说在 Sinatra 下):
Mongoid does not seem to support correctly YAML loading in its current public version (2.3.4). You can take a look at this commit for more details:
Refactor options and env into their own modules
Put the following in your Gemfile to benefit from this recent commit (for me under Sinatra):
有两个指定 DBMS 详细信息的文件,我编辑了它们,我的应用程序运行良好。
There were two files specifying DBMS details, I edited them and my application worked fine.