Create new replicaset from another replicaset

Hello! I have a question - there is a replicaset from which I need to move one large database to a new replicaset. What I did - added three new nodes to the existing replicaset, set priority and votes to 0 to bypass the limitation on the number of nodes in the cluster. I caught up the new nodes with a lag of 0 seconds, removed them from the old replicaset, and changed the replsetname in mongo.conf to the new one. On one of the new nodes, I tried to add the remaining two new nodes using rs.add, but I get an error:

> rs.add("mongo-vm-a-01:27017")
{
	"topologyVersion" : {
		"processId" : ObjectId("652cc54c89b2c853fc478079"),
		"counter" : NumberLong(1)
	},
	"ok" : 0,
	"errmsg" : "New config is rejected :: caused by :: replSetReconfig should only be run on a writable PRIMARY. Current state REMOVED;",
	"code" : 10107,
	"codeName" : "NotWritablePrimary"
}

I understand why this error occurred - my three new nodes belong to the old replicaset, but I don’t understand how to fix this error. In some sources, I saw that you can try to delete system databases - local, admin, config, but I’m afraid to break something. I ask for your help; I couldn’t find similar topics in the forum.

Hi @Arthur_Fedorov, welcome to the forums & community.

This is a variation of restore replica set from backup. You have the datafiles already though.

  1. Start each member without --replSet
  2. Drop local db on each of them.
  3. Start with --replSet again.
  4. Initiate replica set on one member.
  5. Add each of the remaining members.

If you’re feeling a little shy about the procedure run a test with a smaller dataset to get confidence with it.

3 Likes

@chris , thank you, for your answer!

Have a last question - from this post Is it possible to split an existent ReplicaSet? - #8 by Prasad_Saya
I followed all the instructions as described there. A new master of a new replica set started successfully. However, when I try to add another machine to the new replica set, which I previously removed from the other replica set (and, of course, I deleted the “local” database), the rs.add() command on the new master hangs, and nothing happens. I use ctrl+c to interrupt it, but rs.status() shows that the machine with the replica is in the “startup” state, but there is nothing on the replica itself.