Lab: Creating First Application User

I have run this multiple times and I can not figure out what the issue is.

  1. I ran ps -ef | grep mongod to check that it was correct on port 27000
  2. I logged on using the admin username and password on port 27000
  3. I switched to the admin database
  4. I ran:
    { user: "m103-application-user ",
    pwd: “m103-application-pass”,
    roles: [ { db: “applicationData”, role: “readWrite” } ]

and I checked the user and got this:
“_id” : "admin.m103-application-user ",
“user” : "m103-application-user ",
“db” : “admin”,
“roles” : [
“role” : “readWrite”,
“db” : “applicationData”
“mechanisms” : [

And I keep getting this:
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

It looks correct to me except for the errors! What am I doing wrong?

You have an extra space at the end of the user name.

1 Like

I connected via the config file with specifies port 27000 yet I

get this error in relation to the default port 27017. Is there something I am missing?

Yes. Your configuration file specifies 27000 as port number but you try to connect to the default port 27017.

You are Brilliant! Thank you!!! I removed the space at the end of the user name and it worked perfectly! :o)

i ran

mongod -f mongod.conf
mongo admin -u m103-user -p m103-pass.
By connecting via the config file, doesn’t that mean I am connected to port 27000.

Initially I used

Mongo host to connect
use admin

That is correct. But this is not called connecting via the configuration file. This is called starting the mongod server with a configuration file. This is the listening part of the communication.

The above, connects to the default port 27017. This is why you connect SocketException.

That is not what your screenshot shows.

Try to use more command line options so, mongo shell will know what you are trying to do. It will never let you down.
Try following parameters:-

Yes, this is what I tried earlier but it also did not authenticate. I guess I am missing something, so I will go through the lectures one more time and try again. Thanks for the help.

Thank you.

You ran mongo without specifying the port to use. By default, it communicates to port 27017. If you only have a mongod listening on port 27000, and mongo is looking for a service on port 27017, then mongo isn’t going to find your mongodb. Specify the port mongo should talk to with the --port option.

$ mongo admin --host localhost:27000 -u m103-admin -p m103-pass

Had the same socket error. This fixed it for me (or just “–port 27000”), w/o a port specified, it tries to connect to the default port.

bash-4.4# ps aux| grep mongod| grep -v grep
  162 root      0:01 mongod --port 27000 --dbpath /var/mongodb/db --auth --logpath /var/mongodb/logs/mongod.log --logappend --fork

Error: couldn't connect to server, connection attempt failed: SocketException: Error connecting to

I had a similar error,

I continued to get an error
Error: couldn’t add user: No role named readWrite@applicationData

I has an extra space in
“db” : “applicationData ”

After executing below 2 queries…the user gets added successfully, but when i run the test is get Fail messages. Please let me know what’s wrong in this…

mongo --port 27000 --username m103-admin --password m103-pass --authenticationDatabase admin
db.createUser({ user : “m103-application-user”,pwd : “m103-application-pass”,roles : [ { db : “applicationData”, role : “readWrite”}]})

Post a screenshot of the whole IDE so that we see the whole context.


I suspect the user has been created in the wrong database.

Run the command db.getUsers() and post the result.

If no user has the id admin.m103-application-user, create the user again but after running the command use admin.

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

MongoDB shell version v4.0.5
connecting to: mongodb://
Implicit session: session { “id” : UUID(“f52bcb0a-598b-4a60-b1f7-60fb81d6235e”) }
MongoDB server version: 4.0.5
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
Questions? Try the support group
Server has startup warnings:
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten]
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** Start the server with --bind_ip to specify which IP
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten] ** server with --bind_ip to disable this warning.
2021-02-22T14:16:51.421+0000 I CONTROL [initandlisten]

Enable MongoDB’s free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()

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”

Here’s the output:

“_id” : “test.m103-application-user”,
“user” : “m103-application-user”,
“db” : “test”,
“roles” : [
“role” : “readWrite”,
“db” : “applicationData”
“mechanisms” : [

That confirms that the user was created in the wrong database.

So rerun the createUser command after running use admin.