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: stringThe 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