I have put all the steps to initiate a replica-set in a shell script. Basically, I am trying to convert a standalone instance A to replica-set that includes one arbiter B and one secondary node C. These are the following steps in the script:
- Start the standalone instance without auth parameter.
Create an admin user for mongodb admin database with the following role:
Successfully added user: { "user" : "mongodb_admin", "roles" : [ { "role" : "root", "db" : "admin" } ] }
- Stop the standalone instance A.
- Start all the three nodes(A, B,C) with replica-set option and key-file access control.
- Initiate replicaset on instance A by calling rs.initiate.
- Call rs.status to check if the health of all members is 1 (currently there is only A in replicaset)
- Add the arbiter node B and secondary node C to replicaset.
- Wait until all the nodes are healthy.
Everything is fine upto step 5. I am able to successfully initiate a replicaset. But step 6 throws the following error:
2018-08-27T11:43:47.080+0100 E QUERY [thread1] Error: auth failed :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20 @(auth):6:1
@(auth):1:2
When I put a sleep of 15 seconds in between steps 5 and 6, it works perfectly fine. But I still want to make sure that I am doing things correctly. If putting sleep is fine, then how can I make sure that 15 seconds is fine to wait before checking the status in step 6. Also I am unable to understand why its giving an auth error even though I used the same user and password for initiating the replica-set?
MongoDB version: 3.6.2