error in using rs.initiate() in mongo

21.8k views Asked by At

I want to turn on the replication in monga. So when I tried to use rs.initiate I get the following errorrs.initiate()

{
    "ok" : 0,
    "errmsg" : "This node was not started with the replSet option",
    "code" : 76,
    "codeName" : "NoReplicationEnabled"
}

I am new to this so I don't know how to correct it. I am following these guidelines https://blog.jixee.me/how-to-use-mongo-connector-with-elasticsearch/

5

There are 5 answers

1
gzc On

Refer official doc deploy-replica-set to setup mongo replica set.

specifies the replica set name through the --replSet command-line option:

mongod --replSet "rs0"

You can also specify the replica set name in a configuration file.

0
arman On

This problem was solved when I installed another doc manager. The command for the same is

sudo pip install 'mongo-connector[elastic2]'

I don't know exactly how it happened but when I tried to connect to Elastic search using mongo-connector I faced the following problem: No handlers were found for logger "mongo-connector.util" Then I installed another doc manager for mongodb and along with mongo-connector problem this problem was also solved. I think there was some clash between the elastic search doc manager and mongo doc manager.

0
Sathnindu Kottage On

You have to edit mongod.conf first. In windows, you could find it in program files. In MacOSX, Probably you have installed MongoDB via homebrew.

So do the following steps on your terminal,

nano /opt/homebrew/etc/mongod.conf

Add the following code at the end of the document

replication:
  replSetName: rs0
  oplogSizeMB: 100

Finally save it

Now You have to restart MongoDB

Now run the code on mongo

rs.initiate()

0
Araz Jafaripur On

You can add replSet to MongoDb config file in: /etc/mongodb.conf

replSet = test

If not work in latest mongodb add this:

replSetName = test
0
piyush sachdeva On

If you are running on windows, it might have been running as a service and probably you are still connected with your old server.

use the below command to shutdown any running instance and then start all the instances again:

db.adminCommand( { shutdown : 1} )