Create user - I don't have permisions

Hello,

I am working through the lab for starting a replica set. The theory all makes sense. Just following the instructions.

When I am asked to add user I get:
m103-repl:PRIMARY> db.createUser({
… user: “m103-admin”,
… pwd: “m103-pass”,
… roles: [
… {role: “root”, db: “admin”}
… ]
… })
2020-08-24T09:05:25.024+0000 E QUERY [js] Error: couldn’t add user: not authorized on test to execute command { createUser: “m103-admin”, pwd: “xxx”, roles: [ { role: “root”, db: “admin” } ], digestPassword: true, writeConcern: { w: “majority”, wtimeout: 600000.0 }, lsid: { id: UUID(“7c7ac64f-b368-4c81-adfc-e19922028049”) }, $clusterTime: { clusterTime: Timestamp(1598259908, 1), signature: { hash: BinData(0, 1E6FB76579FFD388B1EF10ADA2EA87B40E42FA68), keyId: 6864471286588899329 } }, $db: “test” } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1491:15
@(shell):1:1

I have started the primary node and connected to it. I also started the replica set.

Looking for some pointers on what I might be doing wrong.

Many thanks
Russell

  1. it looks like you are trying to create the user in the wrong database. it says test database but it should be admin database.

  2. if user already exist, you must authenticate

Hi @Russell_Smithers_CORP,

This :point_down:

Please make sure you haven’t already created the user. If in case you have then try to authenticate using that user.

~ Shubham

Thanks for the observation.

I was using the create user statement provided in the lab. The lab notes do not say if we should expect a user to have already been created. Therefore I assumed as we were provided with create user statement, we had to create it.

It’s a little confusing between what the video shows us and what the instructions suggest we need to do.

I will take a another look.

Also I didn’t create a test user, the one in the script is m103-admin and authentication db admin

I tried again. From fresh start, except it seems to remember the config changes I made.

Recap - I still need help! Please!

  1. I never created a test user
  2. I assumed there was no user
  3. I tried to create the user as detailed in the lab
  4. I can’t authenticate with the m103-admin user - it was never created
  5. We were not told to use test db for auth or what the credentials were if that was pre - setup
  6. I have tried following the instructions several times.

There is something missing. This isn’t exactly difficult concepts and im actually reading the lab instructions and thinking through what im doing.

Basically im stuck on step 4

I never got as far as successfully creating a user.
On the basis I might have done, I tried connecting with username password , still no luck.

I have no idea why the test db is being mentioned in the error

It is not test user
steevej-1495 was referring to test DB

By default when you connect to mongodb you will be in test db
You can verify this by running the command db

So you need to switch the db when you create the m103-admin user
use admin---->switched to admin
db----verify to which db you are connected
run create_user command

Hope it clarifies your doubts

Thank you, that’s really useful to know. That should help me along.