MongoDB をローカルにインストールしましたが、Rails 4 / Ruby 1.9.3 / Windows 7 で Mongoid/Moped を使用しようとすると、次のエラーが発生します。
"Could not connect to a primary node for replica set #<Moped::Cluster:27191916 @seeds=[<Moped::Node resolved_address=nil>]>"
おそらく resolve_address =nilが原因です- 他のフォーラムでは、これは hosts ファイルのタイプミスによるものであると述べられています - このファイルが Windows のどこにあるか分かりますか?
アプリには単純なモデル「記事」のみが含まれています
class Article
include Mongoid::Document
field :name, type: String
field :content, type: String
end
そして例外はArticles.all.each.do |article|
...でキャッチされます
mongod と mongo shell を実行すると、アプリの外部で正常に動作するため、構成に問題があると想定しています...私のRailsサーバーログは次のように吐き出します:
Started GET "/articles" for 127.0.0.1 at 2014-01-14 19:04:18 -0800
Processing by ArticlesController#index as HTML
MOPED: Could not resolve IP for: localhost:27017 runtime: n/a
MOPED: Retrying connection attempt 1 more time(s). runtime: n/a
MOPED: Could not resolve IP for: localhost:27017 runtime: n/a
Rendered articles/index.html.erb within layouts/application (10294.6ms)
Completed 500 Internal Server Error in 10325ms
私が知る限り、レプリカ セットに関しては何もしていません。
Rails.env はdevelopment
、私の構成ファイル (mongoid.yml) は次のとおりです。
development:
sessions:
default:
database: mid_dev
hosts:
- localhost:27017
options:
options:
Mongoid は正式に Rails 4 の準備ができていないかもしれませんが、このハードルを乗り越えた人はいますか?