How to run a single node replica set?

i want to run a singleNode replicaset in my development environment.
Should i set voting count as 3 for my replica in this case or voting count should be default which is 1?

Hi @Divine_Cutler, the values for votes, if I’m not mistaken are 0 and 1.

In the case of a single node replica set, since there is only a single node the vote count would need to be set at 1. Changing the vote count, even if it could be greater than 1, wouldn’t have any impact as it’s the only node that can vote. If the machine is running it’s automatically the primary node. If it’s down, well then it doesn’t matter how many votes it gets. :wink:

While a single node replica set might be fine for development purposes, it is strongly cautioned against putting that into production.

What are you trying to accomplish with having a single node replica set?

1 Like

@Doug_Duncan for testing changeEvents in mongodb

Hi @Divine_Cutler, you can follow this documentation to convert your stand alone to a single node replica set.

If you going to create a repl set to test think you need atlest two members to witness replication and voting would only matter if there is more than one member.Else single node I dont think would be much different from a single mongod instance.

@Kirk-PatrickBrown For what @Divine_Cutler is doing(change streams) using a replicaset of one is perfectly fine.

But for a production system where you want some kind of HA, yes you need three nodes. PSA or PSS.

2 Likes

@chris @Doug_Duncan yes, but i do have a doubt when comparing a singleNodeReplicaset with a 3node-replicaset.

When i run a 3node replicaset node1,node2,node3 and if node1 goes down, then among node2,node3 a primary node is elected.

When node2 goes down, then node3 remains as secondary.

is it possible to have the node3 as a primaryNode when node1,node2 is down? if it is not possible, then i would like to know the reason on how is it possible for a singleNodeReplica set to act as a primaryNode.

@Divine_Cutler when you need to have a majority of the nodes up for a replica set to have a primary. This means in a three node replica set that two members must be available.

Check out the Consider Fault Tolerance section of the Replica Set Architectures document.

Having a single node running from a three node replica set is not the same as running a single node replica set.

1 Like

@Doug_Duncan thank you. i understand this post. but here is my doubt.

Let’s say that i have a singleNodeReplicaSet - it accepts both read/write. then i add 2 additionalnodes to this singleNodeReplicaSet which becomes a 3NodeReplicaSet.

So, Once a singleNodeReplicaSet that runs on its own is converted to 3NodeReplicaSet, i could never scaledown the 3NodeReplicaSet back to a singleNodeReplicaSet and make this singleNodeReplicaSet to accept read/write requests?

@Divine_Cutler, you can force reconfigure your remaining member to remove the downed nodes, but that’s not recommended unless absolutely necessary.

If you’re running a three node replica set and two nodes go down I would first look into why I have two nodes down at the same time. While bad things can, and do, happen, it’s rare in my experience for two of the three nodes in a replica set to go down at the same time. Your time is better spent trying to bring the downed nodes back online. If you can get just one of them up and running you have a majority again and one will be promoted to PRIMARY status.

Forcing your three node replica set back down to a single node replica set is very dangerous, especially in a production environment as you’ve lost any sort of HA. I would strongly caution against doing that.

@Doug_Duncan thank you.

i have one more question and it troubles me a little bit.

Please assume this scenario.

i have a 3nodeReplicaSet (node1,node2,node3). There are no problems in the configuration, so everything is functioning as expected.

Assume, there are huge number number of write/update/delete operations going on.Then, at one point, the oplog collection in primaryNode(node1) reached the memory limit and as it is a capped collection, the old data in oplog collection gets overridden and the data from oplog gets synced successfully to the secondaryNodes(node2,node3) without any problems.

Suddenly Node3 goes down for some reason(may be the developer shut it down), but the application is functioning successfully as node1,node2 are running fine. But still there are huge number of write/update/delete ongoing.

My understanding of data sync between nodes in replicaSet is, the secondaryNodes replicate the data from primaryNode by reading the oplog collection of the primaryNode.

Coming back to our scenario,
Assume, that the oplog got filled completely thrice counting from the moment node3 was down till the moment node3 was started again. Now, if the node3 was started again, then

  1. Would there be any error thrown while syncing data to node3?
  2. Will all data from primaryNode get synced to node3? (i assume not)
  3. If all data from primaryNode doesnot sync to node3, then how to sync data to node3 and make it up and running?

@Doug_Duncan i got answer for my above question.
https://docs.mongodb.com/manual/core/replica-set-sync/

even though i went throught that article previously, i forgot about it yesterday

1 Like