我剛配置Mongoid對於Rails項目,跑rails g mongoid:config
編輯我mongoid.yml
要像下面。蒙戈::錯誤:: NoServerAvailable
development:
clients:
default:
database: abacus_development
# Provides the hosts the default client can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- localhost
options:
test:
clients:
default:
database: abacus_test
hosts:
- localhost
options:
read:
mode: primary
max_pool_size: 1
再接着想一切運行良好,腳手架一個叫Activity
控制器和模型。隨着我跑rails s
。該應用程序在localhost:3000
運行良好,但現在我得到localhost:3000/activites
它吐出這一點。
ActionView::Template::Error (No server is available matching preference: #<Mongo::ServerSelector::Primary:0x007fbda47c4110 @tag_sets=[], @options={:database=>:abacus_development}, @server_selection_timeout=30>):
15: </thead>
16:
17: <tbody>
18: <% @activities.each do |activity| %>
19: <tr>
20: <td><%= activity.amount %></td>
21: <td><%= activity.indicator %></td> app/views/activities/index.html.erb:18:in `_app_views_activities_index_html_erb___73038992978597028_70226242222820'
任何想法?
是啊,我。但是'sudo service mongod start'不適用於我。我使用'沖泡安裝mongodb'但似乎有可能是與一個問題,因爲我甚至不能做'mongo'或'mongod'沒有它沒有安裝MongoDB的。 – Souljacker
如果你只運行'mongod',你得到的錯誤是什麼? –
我解決了它。我沒有在我的計算機上正確配置MongoDB,並且沒有設置啓動代理,因此每次需要使用它時,都需要同時執行'mongod'和'mongo'。 – Souljacker