Mongo - rs.initiate() Error Code 76

Viewed 4233

I am new to mongoDB and am trying to use the following.

res = rs.initiate(
{
    "_id" : "ireland",
    "members" : [
        { _id:0,host:myName+".local:"+"27000" },
        { _id:1,host:myName+".local:"+"27001" },
        { _id:2,host:myName+".local:"+"27002" }
    ]
}

);

I then get the following error message.

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

} I have looked around online with no luck. I found some similar questions on here but none of the answers helped.

3 Answers

You need to start mongo server on all the nodes(port) using the --replSet option before initiating the replication set. To do so, start the mongo server on each port using following command (each in a new cmd prompt):

 mongod --dbpath [databasepath] --port 27000 --replSet "ireland"
 mongod --dbpath [databasepath] --port 27001 --replSet "ireland"
 mongod --dbpath [databasepath] --port 27002 --replSet "ireland"

Once the servers are running you can initiate the replication using your command:

res = rs.initiate(
{
    "_id" : "ireland",
    "members" : [
        { _id:0,host:myName+".local:"+"27000" },
        { _id:1,host:myName+".local:"+"27001" },
        { _id:2,host:myName+".local:"+"27002" }
    ]
}

Make sure the _id field of the replication configuration is same as the replSet name.

For me the solution was to kill a redundant instance of MongoDB.

On Linux or Windows (using git bash) enter command to obtain process ID:

ps -alW | grep mongod. 

On Linux or Mac kill the process using:

kill -9 3139

On Windows, kill the process using:

Taskkill /PID 3139 /F

My environment was Windows and solution was to restart MongoDB process:

Task Manager->Services->MongoDB [run restart]

Related