Mongo Replica Sets on Render


I am trying to deploy a MongoDB replica set. On first deployment I run the command:
mongod --bind_ip --oplogSize 128 --replSet rs0 --storageEngine wiredTiger

This works fine and after my Render service launches I can initialize my replica set with:
rs.initiate({ _id: 'rs0', members: [ { _id: 0, host: 'mongo0:27017' } ]})

However, if I redeploy this mongo instance it will not rejoin the replica set and give this message:
{ "operationTime" : Timestamp(1615929974, 2), "ok" : 0, "errmsg" : "Our replica set config is invalid or we are not a member of it", "code" : 93, "codeName" : "InvalidReplicaSetConfig", "$clusterTime" : { "clusterTime" : Timestamp(1615929974, 2), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }

I am trying to figure out how to make sure the mongo instance will re join the replica set on restart.

I am not sure I understand what you do, but it looks like you are trying to run rs.initiate() when you restart. If that is the case you should not. Simply restarting your mongod will make it rejoin its replica set.

Hello Steevej,

Thanks for your response!
No, I’m only running the rs.initiate() on the first deployment and then:

mongod --bind_ip --oplogSize 128 --replSet rs0 --storageEngine wiredTiger, on subsequent restarts.

@Sean_Doughty What is Render ?

How is storage managed, is data persisted and remounted when you redeploy?

Render is a cloud platform:

Storage is managed with a persistent disk mounted to data/db, data is maintained between redeploys.

Using docker I replicate this error if I change the container name. When you redeploy it is not resolving mongo0 to itself like it did when you did the re.initiate

Hope this can help in your troubleshooting.

1 Like