My goal: convert this instance to the PRIMARY in a replica set.
I have another instance running, freshly set up, currently doing nothing (if this works, I’ll add a 3rd).
My thinking was that, stopping the instance, uncommenting the ‘entrypoint’ line and bringing the instance back up, would convert the standalone instance into a replica set instance, as described in this tutorial .
However, when doing this, I get:
(in mongosh):
test> rs.initiate()
MongoServerError: already initialized (PS: I had tried this before...)
test> rs.status()
MongoServerError: Our replica set config is invalid or we are not a member of it.
What message you got when you ran rs.initiate() first time?
Once you start your mongod with replset and run rs.initiate() it should become primary
Check this link.I don’t know about docker
Is there a config file somewhere that stores info about whether a node is in a replica set or not? Can you revert a node in a replica set to again be a standalone version (such that, when started again enabling replica set and rs.initiate(), it will actually say it’s in a replica set)?
Mongod.conf is the configuration file where we define replica parameters but in your case whatever commands mentioned at entry point are run when you initialise your docker
So comment this entry and restart to get back to standalone but advice you not to do experiments on prod
As mentioned before I don’t know about docker setup but many docs available
Check this link
if you start your instances with this parameter set, no matter how many instances you have, you use rs.initiate() only once on one of them and then use rs.add() to add other members.
you could also use a configuration on initialization if you knew what would their IP addresses be. it is a tedious thing to set up but not impossible (play on compose file):
Dropping the local db and restarting with the replica set option worked for me.
Next issue: I’m running version 6.0.3 and tried to add a Raspberry Pi in the mix. However, the last version that works is 4.4. rs.status() complains that:
remote host has incompatible wire version: Server min and max wire version (9,9) is incompatible with client min wire version (17,17).You (client) are attempting to connect to a node (server) with a binary version with which you (client) no longer accept connections. Please upgrade the server’s binary version.
Can I downgrade my 6.0.3 version to be 4.4, or is that not advisable? If not, how would you suggest I add a replica set member with 4.4?
Ok, I think I got why that has worked. the problem here is that you do not add some PRIMARY to your replica set. you wouldn’t want to do this every time you try to add another machine as primary.
start your new machine (container) to be part of the replica set
login to the current replica set.
add the new member and set its priority higher than others to be elected as primary.
all members can be a primary depending on their priorities (or never if set otherwise) through a voting system amongst the members.
PS: as I stated in that other post, I run version 6 on ubuntu-in-a-docker-container, and should in theory run for you too. the responsibility of breaking things is yours.