Lab: Creating First Application User

I’m struggling with this lab.

I connect to the Mongod instance using the following statement in Terminal 0:

mongo --port 27000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

I then add the user to the applicationData database using the following statement in Terminal 0:

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

I get the following response message:

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

However when I run the test I get “incorrect! try again”.

Why?

How did you start your mongod?

If user is created are you able to login with this new user?

Based upon the statement in the first part of the lab - namely that:

The m103-admin user has also already been created for you, with password m103-pass.

I have assumed that the user (m103-admin) has already been created on the admin database.

Therefore my first statement into terminal 0 is:

mongo --port 27000 -u "m103-admin" -p "m103-pass" --authenticationDatabase "applicationData"

Does this statement allow me to “Connect to a mongod instance that has already been started in the background on port 27000”?

I have assumed that I don’t need to start a new Mongod session as one is already running in the background and my statement above attempts to use this background process.

I was referring to the new user-m103-application-user you have created
Can you login with this user?
This may not be in your lab steps but a check that user is created correctly
Sometimes invalid charcters,typos,empty space can cause issues
Please login with new user and check if it is fine or not

Hi - I’m sorry but I’m not sure I know the answer to your question “Can you login with this user?”. I have never ever set up and administered a database of any description so I’m finding it really difficult to understand the basic concepts. I’m assuming I can login with this user because if I use the following statement in terminal 0 : sh-4.4# mongo --port 27000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

I get the following output in terminal 0:

MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27000/?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“b4b3f1c4-1a70-4703-b781-9f0b733dcdb5”) }
MongoDB server version: 4.0.5
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten]
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** Start the server with --bind_ip to specify which IP
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2020-06-07T13:34:32.933+0000 I CONTROL [initandlisten]

Were you able to connect to mongodb?
I dont see mongo prompt in your output

I was asking you to check this (connect to db with new user you created)

mongo --port 27000 --username m103-application-user --password m103-application-pass --authenticationDatabase admin

Can you give me an example of what a “mongo prompt in the output” looks like?

1 Like

How did you complete this step?

Looks like below

MongoDB Enterprise >

I ran the db create user statement - see screenshot below:

How did you get below prompt
Show the screenshot of command you used to connect to mongodb

db.createUser(

Were you able to connect with application-user command i gave
Did you try to connect?

I connected using the following statement:

mongo --port 27000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

see screenshot below:

I have tried to connect using your command and got the following message:

mongo --port 27000 --username m103-application-user --password m103-application-pass --authenticationDatabase admin

2020-06-07T18:29:26.040+0000 E QUERY [js] SyntaxError: missing ; before statement @(shell):1:8

Terminated

You have to exit the mongo shell to run this command.


steevej-1495

1h

You have to exit the mongo shell to run this command.
Can you clarify.
The IDE includes the text editor and the terminal. This lab states that Mongod is already running. If the shell must be exited, where are we working in?

You have to run the mongo and mongod commands at os prompt
Looks like you are trying while connected to mongo

(>) the greater than symbol indicates you are at mongo prompt
Please exit and run from sh#

Also in your previous post you mentioned you were able to connect but i don’t see you could connect successfully

Most likely when you created the user you connected to some default instance
That’s why your test is failing

First make sure mongod on port 27000 is up and running
ps -ef|grep mongo
Then connect to this instance and create the user

2 Likes

Hi @Simon_71444 and @Sara_L,

Please let us know if you are still having any doubts.

~ Shubham

Hi Simon,

I am also not able to login as an admin with the screenshot below:

may i know is there anything i missed?

storage:
dbPath: /var/mongodb/db
net:
bindIp: localhost, 192.168.103.100
port: 27000
security:
authorization: enabled
systemLog:
destination: file
path: /var/mongodb/logs/mongod.log
logAppend: true

The fork has been removed due to the error message keep saying remove the --fork so i removed it, after that i run the below command to add the fork and it seems working…

mongod -f mongod.conf

mongod --dbpath /var/mongodb --logpath /var/mongodb/logs/mongod.log --fork

and when i try

mongo --port 27000 --username m103-application-user --password m103-application-pass --authenticationDatabase admin

Error message as below:

MongoDB shell version v4.0.5
connecting to: mongodb://192.168.103.100:26001/admin?gssapiServiceName=mongodb
2020-06-08T10:15:34.950+0000 E QUERY [js] Error: couldn’t connect to server 192.168.103.100:26001, connection attempt failed: SocketException: Error connecting to 192.168.103.100:26001 :: caused by :: Operation timed out :
connect@src/mongo/shell/mongo.js:328:13
@(connect):1:6
exception: connect failed
<plication-pass --authenticationDatabase admin
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27000/?authSource=admin&gssapiServiceName=mongodb
2020-06-08T10:19:47.465+0000 E QUERY [js] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:328:13
@(connect):1:6
exception: connect failed

Kindly help on this.

Thank you

Please revise the lab requirements.

No where it says you have to bindIp 192.168.103.100. It seems you copied the file from somewhere else rather than following the instructions.

No where it says you have to start mongod. Actually the instructions indicate

Connect to a mongod instance that has already been started in the background on port 27000.

Can you show a screenshot of the whole command? Because I have doubts that this is the real command that produced connecting to: mongodb://192.168.103.100:26001.

We can see a little bit that you specified --port 26001. I suspect that if you run the command you tell us you ran that it will work.

Thank you!!! i solved it already.

There is a pinned post for this lab for this Chapter in the discussion board where this IP is listed. I have tried to report the pinned discussion (it is locked, so I cannot comment on it). The discussion post looks largely unhelpful since it is over a year old.