17

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?

Community
  • 1
  • 1
B. L.
  • 433
  • 2
  • 4
  • 9
  • 1
    did you try: `rm -rf /data/db/mongod.lock; mongod --dbpath /data/db --quiet &` You might need to change the mongod.lock and db path – Muntasim Sep 02 '13 at 05:47
  • Yes, I tried that already. I've found the root of the issue, as documented in above link. Thanks! – B. L. Sep 03 '13 at 06:58

3 Answers3

26

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.

Deepender Singla
  • 999
  • 9
  • 28
11

Installing MongoDB solved this for me:

sudo apt-get install mongodb-server
cedarstarr
  • 339
  • 4
  • 9
4

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.

quetzaluz
  • 1,071
  • 12
  • 17