即使在 mongoid.yml 中指定不同的地址后,Mongoid仍会在 27017 连接到本地主机

发布于 2024-12-23 10:31:51 字数 832 浏览 6 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

微暖i 2024-12-30 10:31:51

您能否尝试在 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.

苏别ゝ 2024-12-30 10:31:51

Mongoid 在其当前的公共版本(2.3.4)中似乎不支持正确的 YAML 加载。您可以查看此提交以了解更多详细信息:
将选项和环境重构到它们自己的模块中

将以下内容放入您的 Gemfile 中以从最近的代码中受益提交(对于我来说在 Sinatra 下):

gem 'mongoid', :git => "https://github.com/mongoid/mongoid.git"

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):

gem 'mongoid', :git => "https://github.com/mongoid/mongoid.git"
旧伤还要旧人安 2024-12-30 10:31:51

有两个指定 DBMS 详细信息的文件,我编辑了它们,我的应用程序运行良好。

There were two files specifying DBMS details, I edited them and my application worked fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文