Can't run Rails 4 app with Mongoid

132 Views Asked by At

I want to use MongoDB in my rails application and facing a problem:

Could not connect to a primary node for replica set #]>

This is what I've done to set up my project:

Created a new project with the following command, in order to replace Mongoid with rails active-record:

rails new hellomongoid --skip-active-record

Added 'mongoid', '~4.0.0' and 'bson_ext' gems to my Gefile and ran bundle install successfully.

Generated the mongoid:config with this command:

rails g mongoid:config

Generated new scaffold:

rails g scaffold Car model:string manufacturer:string year:string

Started the MongoDB with the Mongod command, and started the rails application in localhost.

Now I get this annoying error message when I try to reach localhost:3000/cars. It says that it occurs right here:

 <tbody>
   **<% @cars.each do |car| %>**
     <tr>
       <td><%= car.model %></td>
       <td><%= car.manufaturer %></td>

Where I was wrong?

Both the Mongod and my rails Mongoid config set to port 27017...

EDIT:

This is my mongoid.yml file:

development:  
  sessions:    
    default:      
      database: yomongo_development      
      hosts:
        - localhost:27017
      options:        
  options:    
test:
  sessions:
    default:
      database: yomongo_test
      hosts:
        - localhost:27017
      options:
        read: primary        
        max_retries: 1
        retry_interval: 0
0

There are 0 best solutions below