Could not connect to a primary node for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">]>

B. L. picture B. L. · Sep 2, 2013 · Viewed 19.2k times · Source

I'm following though with the RailsApp tutorial with Devise and Mongoid (http://railsapps.github.io/tutorial-rails-mongoid-devise.html) and am encountering the following error when I get to 'Rake db:seed' down at the 'Set Up a Database Seed File' section.

Could not connect to a primary node for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">]>

I've tried the instructions from nixoncd on this page here but has not fixed the issue. It tells me 'file exists' and 'Already loaded'. 'https://groups.google.com/forum/#!topic/mongodb-user/Hhh8iNCciMk

I get this if I type 'mongod' in terminal.

ERROR: could not read from config file

Any help welcome. I'm on a Mac OSX Mountain Lion with Mongoid installed using homebrew - though MongoDB was installed using the download package mongodb.org.

MongoDB shell version: 2.4.6

Thanks

EDIT: I'm not sure if this issue is related or not. Also having issues launching mongoDB. Also posted issue here: mongoDB, could not read from config file -- config in different folder / Uninstall it?

Answer

Deepender Singla picture Deepender Singla · Sep 11, 2013

First See if your database is running by mongo , If yes

Use this command:

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start

Your database will work.