Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 644
B. L. Avatar asked Sep 02 '13 01:09

B. L.


3 Answers

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.

like image 178
Deepender Singla Avatar answered Oct 19 '22 10:10

Deepender Singla


Installing MongoDB solved this for me:

sudo apt-get install mongodb-server
like image 20
cedarstarr Avatar answered Oct 19 '22 11:10

cedarstarr


The answers above will work for you in the majority of the cases where this error occurs.

However, I would like to note that you can also get the Could not connect to a primary node for replica set error when trying to write exceptionally large batches of records to MongoDB in one request. I have encountered this error when writing more than 200,000 1 KB documents to a remote MongoDB server with in one request. The remote server had 8 GB memory and would handle several requests at once. This error can be avoided by cutting down the batch size of your requests.

like image 38
quetzaluz Avatar answered Oct 19 '22 11:10

quetzaluz