Lab: Creating First Application User - Error in case 2 & 3

The following command I have used in the Lab.

mongo --host localhost:27000 --username m103-admin --password m103-pass --authenticationDatabase admin

 use admin
 db.createUser({
  user:'m103-application-user',
  pwd:'m103-application-pass',
  roles:['readWrite']
 })

db.auth( "m103-application-user", "m103-application-pass")

use applicationData
 db.createUser({
  user:'m103-application-user',
  pwd:'m103-application-pass',
  roles:['readWrite']
 })

db.createCollection("log", { capped : true, size : 5242880, max : 5000 } )
db.auth( "m103-application-user", "m103-application-pass")

I can able to authenticate with same username and password and also I can able to create collection with readWrite role. But not sure why I am getting the following lab results,

3 total, 1 passed, 0 skipped:
[PASS] “The user m103-application-user was created on the admin database”
[FAIL] “The user m103-application-user has the correct permissions”

Did you create the ‘m103-application-user’ with the readWrite role on the
applicationData database?

[FAIL] “The user m103-application-user has the correct password”

Did you create the ‘m103-application-user’ with the password
‘m103-application-pass’?

I am not able to figure out what mistake I have made it. Can you please help me on this.

The db.createUser() you did after use applicationData is useless since the user needs to be created in the admin database and you got that right because [PASS] “The user m103-application-user was created on the admin database”.

However the roles are not correct. Revise the lesson or read https://docs.mongodb.com/manual/reference/method/db.createUser/.

As for the password failing, I do not know yet.

I have also tried with below command but I could not authenticate user in applicationData db.

     use admin
     db.createUser({
       "user":"m103-application-user",
       "pwd":"m103-application-pass",
       "roles":[{"role":"readWrite", "db":"applicationData"},{"role":"readWrite", "db":"admin"}]
     })

Check your user creation syntax again
User should have readWrite on applicationData DB only
Show us the error you are getting when authenticating
Are you using db.auth or login method?

1 Like

I have created used in admin database with only applicationData db . It worked . Thanks