Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 782
arman Avatar asked Dec 23 '16 05:12

arman


People also ask

What is Rs initiate in MongoDB?

rs.initiate(configuration) Initiates a replica set. Optionally, the method can take an argument in the form of a document that holds the configuration of a replica set. The rs.initiate() method has the following parameter: Parameter.

What is Rs status () in MongoDB?

Definition. rs.status() Returns the replica set status from the point of view of the member where the method is run. This method provides a wrapper around the replSetGetStatus command.

How do you initiate a replica set?

To reset the configuration, make sure every node in your replica set is stopped. Then delete the "local" database for every node. Once you are confident all nodes are not running and the local database are gone, start the mongod process again (of course using the --replSet flag). Then run rs.


2 Answers

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.

like image 83
gzc Avatar answered Sep 19 '22 05:09

gzc


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} )
like image 38
piyush sachdeva Avatar answered Sep 21 '22 05:09

piyush sachdeva