How to get replSetName before exec rs.initiate() in mongodb replica set

Viewed 50

Because I want to write a script to batch initialize replica set,but the config _id need be the same as startup command --replSet. When I use mongo shell js script to initiate, can not get replica set name of startip command.

1 Answers

You can get the startup replSet option with getCmdLineOpts from inside the service even the replicaSet was not initialized yet , example:

db.adminCommand( { getCmdLineOpts: 1  } ).parsed.replication.replSetName
myExampleRset
Related