When executing the command for connecting and creating admin user my connection is refused?

vagrant@m103:~/data/db$ mongo admin --host localhost:27000 --eval ’

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

MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27000/admin?gssapiServiceName=mongodb
2020-02-05T18:41:00.884+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27000, in(checking socket for error after poll), reason: Connection refused
2020-02-05T18:41:00.884+0000 E QUERY [thread1] Error: couldn’t connect to server localhost:27000, connection attempt failed :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed

The most likely cause is that mongod is not running at localhost:27000.

You may run ps -aef | grep [m]ongod to find out.

1 Like

After restarting the machine and did connect with mongod --port 27000 and it connected as you can see below but with validate issue is their again

vagrant@m103:~$ mongo admin --host localhost:27000 --eval ’

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

MongoDB shell version v3.6.17
connecting to: mongodb://localhost:27000/admin?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“f10dc6a1-b67b-4858-a89a-6638d6238145”) }
MongoDB server version: 3.6.17
Successfully added user: {
“user” : “m103-admin”,
“roles” : [
{
“role” : “root”,
“db” : “admin”
}
]
}
vagrant@m103:~ validate_lab_launch_mongod You need to specify db path /data/db. I ran this also: vagrant@m103:~ ps -aef | grep [m]ongod
vagrant 2104 2083 0 18:57 pts/0 00:00:05 mongod --port 27000

still i get connection error

You do not start mongod correctly.

As the error message indicates

Hi @Vaibhav_63055,

In addition to @steevej-1495,

Please read the instructions mentioned in the lab carefully. You are not starting the mongod instance as per the requirements mentioned in the lab.

For further assistance please refer our documentation on mongod

Hope it helps!

Please feel free to get back to us if you have any other query.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

Before using below commands i had to delete all the contents of log and other --fork files from the /data/db/ (due to the wrong use of command with fork and other flags)
Commands
mongod --port 27000 --dbpath /data/db/ --logpath /data/db/mongod.log --bind_ip 192.168.103.100,127.0.0.1
and was able to run the
mongo admin --host localhost:27000 --eval ’
db.createUser({
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}
]
})

and in separate shell i ran the validate_lab_launch_mongod and got the key
But could the old log files and --fork can cause such trouble that is what i only deleted ?

No. You did much more than that. Before you were starting mongod only with –port as seen below.

And now you added –dbpath /data/db/ and –logpath /data/db/mongod.log. The way you started mongod before was not using /data/db/ or /data/db/mongod.log as they are not the defaults.