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

19,375

Solution 1

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.

Solution 2

Installing MongoDB solved this for me:

sudo apt-get install mongodb-server

Solution 3

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.

Share:
19,375

Related videos on Youtube

B. L.
Author by

B. L.

Updated on September 16, 2022

Comments

  • B. L.
    B. L. about 1 year

    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?

    • Muntasim
      Muntasim
      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