You need to specify db path?

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.14
connecting to: mongodb://localhost:27000/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("eada1b39-8e13-496c-b3c5-8f1c45e6c472") }
MongoDB server version: 3.6.14
2019-10-16T19:03:17.856+0000 E QUERY    [thread1] Error: couldn't add user: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell eval):2:1
vagrant@m103:~$ validate_lab_launch_mongod
You need to specify db path /data/db.

@Rakshith_79674 is there something you need help with? And which lab does it relate to?

Yes i have specified the path while running mongod and I switched to another terminal and tried the above cmd,
First the user couldn’t create
Second I get when I run validate cmd
“You need to specify db path /data/db”.

Let’s see how you did it

First terminal

mongod --auth --port 27000 --bind_ip “127.0.0.1, 192.168.103.100” --dbpath data/db

Waiting for connection on port 27000
When I use --logpath and --fork it fails

Second terminal

mongo --port 27000

Two things:

couldn’t add user:

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.14
connecting to: mongodb://localhost:27000/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("7ad3423e-4d9f-407d-ae3b-e5e651e1c75f") }
MongoDB server version: 3.6.14
2019-10-17T13:04:32.051+0000 E QUERY    [thread1] Error: couldn't add user: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell eval):2:1

I don’t know how but I got some string

I don’t understand. Are you saying that you got the right answer?

vagrant@m103:~$ validate_lab_launch_mongod
You need to specify db path /data/db.

This has been solved by
--dbpath /data/db/

When should I use the below cmd
I am confused

 vagrant@m103:~$ mongo admin --host localhost:27000 --eval '
    >   db.createUser({
    >     user: "m103-admin",
    >     pwd: "m103-pass",
    >     roles: [
    >       {role: "root", db: "admin"}
    >     ]
    >   })
    > '

I am sorry to state the obvious but it is to be used to create a user. Some lab requires the creation of a user.

Is it not required to create the user now?
2019-10-17T13:04:32.051+0000 E QUERY [thread1] Error: couldn’t add user: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15

HI @Rakshith_79674,

This error message means that the user has already been created and exists.

You just need to authenticate the user now using below command:

db.auth( 'm103-admin', 'm103-pass' )

Thanks,
Muskan
Curriculum Support Engineer

vagrant@m103:~$ mongo
MongoDB shell version v3.6.14
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("260389e4-c068-4fcb-8c93-2c30c798a527") }
MongoDB server version: 3.6.14
MongoDB Enterprise > db
test
MongoDB Enterprise > dbs
2019-10-18T10:01:28.401+0000 E QUERY    [thread1] ReferenceError: dbs is not defined :
@(shell):1:1
MongoDB Enterprise > use test
switched to db test
MongoDB Enterprise > show collections
2019-10-18T10:01:43.021+0000 E QUERY    [thread1] Error: listCollections failed: {
        "ok" : 0,
        "errmsg" : "not authorized on test to execute command { listCollections: 1.0, filter: {}, lsid: { id: UUID(\"260389e4-c068-4fcb-8c93-2c30c798a527\") }, $db: \"test\" }",
        "code" : 13,
        "codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:941:1
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:953:19
DB.prototype.getCollectionNames@src/mongo/shell/db.js:964:16
shellHelper.show@src/mongo/shell/utils.js:853:9
shellHelper@src/mongo/shell/utils.js:750:15
@(shellhelp2):1:1
MongoDB Enterprise > db.auth( 'm103-admin', 'm103-pass' )
Error: Authentication failed.
0

Hi @Rakshith_79674,

You need to be in the admin database, not test.

Please run “use admin” and then run your commands/validation script.

Thanks,
Muskan
Curriculum Support Engineer

MongoDB Enterprise > use admin
switched to db admin

MongoDB Enterprise > db.auth( ‘m103-admin’, ‘m103-pass’ )
Error: Authentication failed.
0
MongoDB Enterprise >

Hi @Rakshith_79674,

Can you please confirm if you created the user in admin database as well and not in the test db?

If you still face issues, I would highly recommend you to go back and look at the instructions mentioned in the lab and re-start your process by carefully following all the instructions.

Let me know if you have any questions.

Thanks,
Muskan
Curriculum Support Engineer