Chapter 2 Lab: Deploy a Replica Set db.createUser() permissions?

I admit I am stuck and it is probably something stupid simple. I have reset the workspace and am running into multiple problems…

#1. When I edit the mongod_X.conf files and try to launch mongod I get a file not found, so for example I edit the mongod_1.conf file and then run mongod -f mongod_1.conf I get a no such file or directory error. So I create the file in /etc/ and the file error goes away. I move on to the

db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

stage of the lab and I am logged in no problem, it shows primary, but when I run the db.createUser() command I get the following output.

[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(“56553f1e-9ef3-44ea-9f30-d3d27e95eef5”) }, $db: “test” } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13

It leaves me more or less stuck at this point…

How can I start over fresh and clear this error?

The user has to be created in the admin database. By default when starting the shell you are in the test database. Run the command use admin before creating the user. You are NOT as stuck as you think, you made good progress despite the file missing issue.

[EDITED]

I added the NOT above which was my original intent.

1 Like

Hi @Daves_Workshop,

I hope you found @steevej-1495’s response helpful. Let us know if you are still facing any issues.

~ Shubham