First Application User

Below is what i am doing -Need some help here , Can some one please take a look and tell me what I am doing wrong .

user@M103# mongo admin --port 27000 -u m103-admin -p m103-pass
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27000/admin?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“28c73730-069a-4e79-aa39-24fa5f19a6fb”) }
MongoDB server version: 4.0.5
Server has startup warnings:
2021-05-13T13:49:29.047+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

use admin
switched to db admin
db.createUser(
… { user: " m103-application-user",
… pwd: “m103-application-pass”,
… roles: [ { db: “applicationData”, role: “readWrite” } ]
… }
… )
2021-05-13T14:28:39.767+0000 E QUERY [js] Error: couldn’t add user: User " m103-application-user@admin" already exists :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1491:15
@(shell):1:1

Looks like you might already have done this step.

Simply try to validate the lab.

Hi,
Hope you might have already figured out your issue. But, in case if you need suggestions

  1. Check if the user already exists.

mongo mongodb://localhost:27000 -u m103-admin -p m103-pass

show dbs

use admin

db.getUsers()

  1. If any document is returned, then check for “user” : “m103-admin”

  2. the user can be dropped from ‘admin’ database :

db.dropUser(“m103-admin”)

  1. User can be created again with db.createUser() command

use admin

<deleted, reason: potential answer>

  1. Output :

Successfully added user: {
“user” : “m103-application-user”,
“roles” : [
{
“db” : “applicationData”,
“role” : “readWrite”
}
]
}

Cheers,

Hi @rajeshwar_dadi,

We hope that you were able to resolve your above query.

In case of any further issues, feel free to reach out.
We will be happy to help.

Good Luck :100:

Thanks,
Kushagra

You really really DO NOT want to do that.

If the user m103-application-user already exist, it is because you already created it, so simply validate the lab.

1 Like

Thanks for all your replies . Below is what I am seeing when i do get user . May be i should drop the user and recreate it .

use admin
switched to db admin

db.getUsers()
[
{
“_id” : “admin.m103-admin”,
“user” : “m103-admin”,
“db” : “admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
],
“mechanisms” : [
“SCRAM-SHA-1”,
“SCRAM-SHA-256”
]
}
]

dropped user and recreated it - still same issue - not sure what i am doing wrong .

db.dropUser(“m103-application-user”)
false
db.createUser(
… { user: " m103-application-user",
… pwd: “m103-application-pass”,
… roles: [ { db: “applicationData”, role: “readWrite” } ]
… }
… )
Successfully added user: {
“user” : " m103-application-user",
“roles” : [
{
“db” : “applicationData”,
“role” : “readWrite”
}
]
}

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

Did you create the ‘m103-application-user’ 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’?

Watch your typing. You have an extra space at the beginning of the user name.

Good observation - Thank you it worked .

1 Like