arman
arman

Reputation: 424

error in using rs.initiate() in mongo

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/

Upvotes: 13

Views: 22975

Answers (5)

Sathnindu Kottage
Sathnindu Kottage

Reputation: 1191

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()

Upvotes: 1

piyush sachdeva
piyush sachdeva

Reputation: 456

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} )

Upvotes: 9

Araz Jafaripur
Araz Jafaripur

Reputation: 906

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

replSet = test

If not work in latest mongodb add this:

replSetName = test

Upvotes: 1

arman
arman

Reputation: 424

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.

Upvotes: 0

gzc
gzc

Reputation: 8639

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.

Upvotes: 3

Related Questions