蒙戈::错误:: NoServerAvailable

时间:2015-07-10 20:02:15

标签: ruby-on-rails mongodb

我刚为一个Rails项目配置了Mongoid,运行rails g mongoid:config编辑了我的mongoid.yml,如下所示。

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'

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

你正在运行mongo吗?如果你在Mac或'sudo service mongod start',可能会使用'mongod'。可能是一个愚蠢的答案,但你永远不知道

答案 1 :(得分:0)

默认情况下,Mongo在端口27017上运行,尝试将您的主机配置更改为mongoid.yml中的localhost:27017。

答案 2 :(得分:0)

尝试

sudo mongod

我认为它应该起作用