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.
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.
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