Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"This node was not started with the replSet option"

I am studying the MongoDBUniversity's M101P: MongoDB for Developers course.

I am using WiredTiger on MongoDB 3.2.

I am currently on the topic of replica sets.

The course requires I create a replica set using the following code:

mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork

But I am using Windows, which doesn't support fork, so using this gist (as recommended by a course admin) I ran these lines simultaneously in 3 different consoles after I had created the directories (with mongod running):

mongod --replSet rs1 --logpath "1.log" --dbpath rs1 --port 27018 --smallfiles --oplogSize64  
mongod --replSet rs1 --logpath "2.log" --dbpath rs2 --port 27019 --smallfiles --oplogSize64  
mongod --replSet rs1 --logpath "3.log" --dbpath rs3 --port 27020 --smallfiles --oplogSize64

Which all seems to work fine; I can see the directories have been filled, and the log files, which all show "waiting for connection" with the relevant port number.

Finally, I am running the following code to unify the servers as a replica set:

config = {_id: "rs1", members: [
           { _id: 0, host: "localhost:27018"},
           { _id: 1, host: "localhost:27019"},
           { _id: 2, host: "localhost:27020"}
                                ]
         }

rs.initiate(config)
rs.status()

Which is throwing:

"errmsg" : "This node was not started with the replSet option",
"code" : 76

Which I can't get my head around, as I have clearly used the --replSet option for each server, and indeed provided the same replSet name used in the config file.

I've looked at other questions on this topic, but there are few, and none that I can find address and solve this issue for me. This one states what looks obvious from the error: my config file should include --replSet=rs1, but from reading the documentation I am given the impression that the _id of the config I have defined serves that purpose:

_id
Type: string

The name of the replica set. Once set, you cannot change the name of a replica set.

_id must be identical to the replication.replSetName or the value of –replSet specified to mongod on the command line.

Furthermore, this is clearly shown functioning correctly in the course material video demonstrations in precisely the manner I am attempting to use it.

I am at my wit's end, and would very much appreciate help.
Jake

like image 279
Jake Stokes Avatar asked Nov 21 '16 02:11

Jake Stokes


1 Answers

So as I finished writing this question, the answer just came to me like a lightbulb, which seems to happen often... but this time I thought I would leave the answer here for anyone else who has struggled with this, considering the somewhat lack of questions/answers on this topic on the forum.

It was a simple case of the default port being used when running my config file.
I was using mongo < init_replica.js to run my config and unify the servers to create the replica set.

By simply adding a port used by one of the valid servers, it ran correctly:

mongo --port 27020 < init_replica.js 

Woe is me for that one, but I hope this helps those also studying the course who find themselves stuck somewhere similar.

Jake

like image 108
Jake Stokes Avatar answered Sep 21 '22 01:09

Jake Stokes