Failed to auth m103-application-user

I have successfully created the user m103-application-user. I have also successed with validation:

validate_lab_first_application_user
[returned the correct validation result]…

below is my admin db:

MongoDB Enterprise > use admin [0/1130]
switched to db admin
MongoDB Enterprise > db.getUsers()
[
{
“_id” : “admin.m103-admin”,
“user” : “m103-admin”,
“db” : “admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
},
{
“_id” : “admin.m103-application-user”,
“user” : “m103-application-user”,
“db” : “admin”,
“roles” : [
{
“role” : “readWrite”,
“db” : “applicationData”
}
]
},
{
“_id” : “admin.root”,
“user” : “root”,
“db” : “admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
]

My problem is, I cannot use the newly created user.
//////////////////////////////////

MongoDB Enterprise > use applicationData
switched to db applicationData
MongoDB Enterprise > db.auth(‘m103-application-user’,‘m103-application-pass’)
Error: Authentication failed.
0

//////// ==> this prevented me from finishing the last lab in this chapter. Anyone else run into this problem?

Thanks a lot.

Actually, I finished the last lab, after I added “authenticationDatabase” option in my mongoimport command.

However I still cannot access the “applicationData” dababase as user “m103-application-user”. I guess I cannot simply use db.auth() where db==“applicationData” but I will have to figure out why…

OK, I realized what went wrong.
When I authorize myself as "m103-application-user” (I really wish they could shorten this user name in future), I must do it on “admin” database because that’s where the authentication happens.

So below is the right way to read the database. Phew…

use admin
db.auth(‘m103-application-user’,‘m103-application-pass’);
use applicationData
show collections

3 Likes

Thanks for this! I was scratching my head on what was wrong

I had this similar interrogation reading this course, and finally the same conclusion :wink: