Error while creating replica set


I have made a mistake while mentioning the replica set in my configuration file.
Now when I try to create the admin user again I am getting the below error:

MongoDB Enterprise m103-repl:PRIMARY> db.createUser({     user: "m103-admin",     pwd: "m103-pass",     roles:[{role: "root", db: "admin"}] })
    2019-11-20T03:05:11.933+0000 E QUERY    [thread1] Error: couldn't add user: not authorized on test to execute command { createUser: "m103-admin", pwd: "xxx", roles: [ { role: "root", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 600000.0 }, lsid: { id: UUID("bd3b7df5-8df0-4f36-8683-2f691eee8433") }, $clusterTime: { clusterTime: Timestamp(1574219089, 7), signature: { hash: BinData(0, 49E97B5792DC4967FAA030999405B255750FD19C), keyId: 6761219503993913345 } }, $db: "test" } :

How do I start again clean from the very beginning?

Explain the mistake you made?
From the error message, you are in the wrong database called test which is the default database. You must create the user on the admin db. However, it seems that you have already created a user so switch to the admin db and try to login/authenticate with that user via the mongo shell:
use admin
db.auth(username, password)

Hi @Rounak_65961,

If the issue is still not resolved then please share what mistake did you made in your configuration file.

It appears to me that the current authenticated user does not have the permission to add a new user on the test database. Can you please tell me what roles/privileges did you give to the first user which you created ?

If you do not remember then do the following and share the output.

  1. use admin

  2. use test

Shubham Ranjan
Curriculum Support Engineer

Thanks for the help.
The mistake i made was that,
I named the replica set name as : m103
Instead of : m103-repl

To try again I deleted the db directories and created them again and tried process again.

However while trying again i did not switch to admin db. That might be reason I am getting the above error.
I will try again by switching to admin db to create the new user tonight and get back to you.

Ok. If this was the only mistake then it would have been a lot easier to fix but if you created the first user in the wrong db, then you’ll need to start from scratch… like you said.

Let us know!

Yup it worked.

I did the below and passed the lab:

  1. Fixed my configuration files first.
  2. Deleted the db folders using sudo
  3. Recreated the db folder as mentioned in the lab
  4. Followed the remaining procedure as mentioned in the lab step by step