Laboratory Creating First Application User

Hi I’m unable to get access to applicationData database, i hope find help. because im sttuck here a long time. thats the steps thhat Im following. Please correct me if im doing somthing wrong

i connect to Mongo in this order
mongo --port 27000
Change to admin database
use admin
loggin like root user
db.auth( 'm103-admin', 'm103-pass' )
Create User
db.createUser( { user: 'm103-application-user', pwd: 'm103-application-pass', roles: [ { db: 'applicationData', role: 'readWrite' } ] } )
Verify the user
db.getUsers() [ { "_id" : "admin.m103-admin", "userId" : UUID("4b775d6d-a6ab-4b0e-82a6-9755ad004b12"), "user" : "m103-admin", "db" : "admin", "roles" : [ { "role" : "root", "db" : "admin" } ] }, { "_id" : "admin.m103-application-user", "userId" : UUID("0e39320e-af2c-417d-85b3-143e8e8bb69e"), "user" : "m103-application-user", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "applicationData" } ] } ]
going to the Vagrant machine

vagrant@m103:~$ validate_lab_first_application_user

User 'm103-application-user' not configured correctly - your application's user
should only have access to the applicationData database.    

Here my troubleshooting.
i connect to Mongo in this order
mongo --port 27000
Change to admin database
MongoDB Enterprise > use admin switched to db admin MongoDB Enterprise > db.auth( 'm103-application-user', 'm103-application-pass' ) 1 MongoDB Enterprise > db.getUsers() 2019-08-23T04:48:51.000+0000 E QUERY [thread1] Error: not authorized on admin to execute command { usersInfo: 1.0, lsid: { id: UUID("f01a6dc5-7272-4fc5-abbf-4d0515d7aa5c") }, $db: "admin" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DB.prototype.getUsers@src/mongo/shell/db.js:1686:1 @(shell):1:1 MongoDB Enterprise >
So, thats fine, i suppouse that i will be use admin database only for authenticate, and try Changing the user
MongoDB Enterprise > use admin switched to db admin MongoDB Enterprise > db.auth( 'm103-admin', 'm103-pass' ) 1 MongoDB Enterprise > db.getUsers() [ { "_id" : "admin.m103-admin", "userId" : UUID("4b775d6d-a6ab-4b0e-82a6-9755ad004b12"), "user" : "m103-admin", "db" : "admin", "roles" : [ { "role" : "root", "db" : "admin" } ] }, { "_id" : "admin.m103-application-user", "userId" : UUID("0e39320e-af2c-417d-85b3-143e8e8bb69e"), "user" : "m103-application-user", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "applicationData" } ] } ] MongoDB Enterprise >

Verify the Databases
MongoDB Enterprise > show databases admin 0.000GB applicationData 0.000GB config 0.000GB local 0.000GB newDB 0.000GB MongoDB Enterprise >

So, there Is. Looks like fine, try to move to applicationDatabase
And there is my issue, the db.getUsers() its empty

`MongoDB Enterprise > use applicationDatabase
switched to db applicationDatabase
MongoDB Enterprise > db.getUsers()
[ ]
MongoDB Enterprise > `

Ok, i try to find a set user command on the database, but there is not a setUser, how i can assign to the database that the user m103-application-user going to be in that Database.

I hope anyone can help me or give me some advice or guide to complete the lab

Hey @p3dr0

To first answer your question about how to assign a User to a db the following is how you did it. db: 'applicationData'

Now is the rest of your setup configured correctly?

run on port 27000
data files are stored in /var/mongodb/db/
listens to connections from the IP address and localhost
authentication is enabled
root user on admin database with username: m103-admin and password: m103-pass

If your configuration does not use authentication, this lab may fail to validate.

I only ask because I cannot seem to think of what else could be causing this. Perhaps another community member could assist. :smile:

What puzzles me is

between the mongo commands and the call to validate.

If you have a mongod running on the host and if you started the shell on the host then the user has been created on the host mongod, not on the vagrant mongod.

1 Like

Hi @p3dr0,

Since you have created the “m103-application-user” in the admin database, so you are not able to view the user in the applicationData db.
Point of confusion: “m103-application-user” has ‘readWrite’ role in applicationData db. However, it is created on admin database.
Please check the following screenshot:

I hope it helps!!
Please let me know, if you have any questions.


1 Like

Hi! Ok
So when i use db.getUsers() from application data DB its fine that no shows any user.

Sure, i had all correctly configure, that was the env that i had been using to made all past labs, and until now, i don’t have any issue.

when i had my laptop again, i put my conf file.
I had the authentication in the config file like
authorization: enabled
Please correct me if that its not the correct way

The user admin is good,
db.auth( 'm103-admin', 'm103-pass' )
this commands return 1

Sure, of course i created the m103-application-user user under admin database,. ok, now i undestand that the users no needs to be showed on the application database users. but the validation command still not running

Verify the user
[ { “_id” : “admin.m103-admin”, “userId” : UUID(“4b775d6d-a6ab-4b0e-82a6-9755ad004b12”), “user” : “m103-admin”, “db” : “admin”, “roles” : [ { “role” : “root”, “db” : “admin” } ] },

{ “_id” : “admin.m103-application-user”, “userId” : UUID(“0e39320e-af2c-417d-85b3-143e8e8bb69e”), “user” : “m103-application-user”, “db” : “admin”, “roles” : [ { “role” : “readWrite”, “db” : “applicationData” } ] } ]`

In the lastone i can see the same as your picture.

I created the user inside the admin database, and exit to the vagrant machine to run the validation script.

Hi Here’s my mongod.comf

vagrant@m103:~$ cat mongod.conf
port: "27000"
bindIp: "localhost,"
dbPath: "/var/mongodb/db"
path: "/var/mongodb/db/mongod.log"
logAppend: true
destination: "file"
mode: slowOp
slowOpThresholdMs: 50
authorization : enabled
fork : true

Hi p3dr0
Is your validation still failing?
Is your mongod running on port 27000 with auth enabled?
Are you able to connect with the application user
Is your users output from same DB
How many mongods are running
ps -ef|grep mongod

Hi, i recreated all the labs, and works, i dont know what was wrong really, i only do a vagrant destroy and then a vagrat up and make a new config and works

1 Like