Short answer / tl;dr
No.
Slightly longer answer
No, because it makes sense to use the shell.
Answer
When you set up a replica set, you usually have more than one member. Until the replica set is initialized, none of the members holds the necessary configuration. The node you initialize the replica set on becomes primary, storing the configuration. Now you add members either using the rs.add
command or by using rs.reconfig
. What happens then is that the primary contacts the added member, the config is synced and some other things. It is best practise that ordinary replica set members should be equal so that of one node fails, there is no drawback that another node becomes primary and so the new primary can stay primary until it goes down for some reason or the other itself.
So if you would start a replica set member, where should it get it's config from? Decide for itself what it has to do? That wouldn't work well in a cluster. How should it discover the other members and their config? Remember, replica set members can be in different data centers. And if there was a --IamPrimaryDoAsISay
option, what would happen if there was another primary currently in the cluster? And how should a situation in which more than one member was started with that option be dealt with? A step down of the other server? May be just because you replaced a cooler? Or should the just started instance do nothing when there already was a primary? What sense would the option have then in the first place?
And all these complications just to prevent a single command from the shell?
Note: If you want a single server, just start a standalone instance (a mongod without the --replSet
option).if you want to explore the possibilities of a replica set, you need more than one member.
mongo --eval
? I am trying to solve this as well here https://mcmap.net/q/1019672/-what-is-the-proper-way-of-setting-a-mongodb-replica-set-using-docker-and-fig/429521 – Custos