Failed when I try to create a user : Lab: Deploy a Replica Set

In the Lab: Deploy a Replica Set , the response is : “command not found”. First I update the configuration files, launch mongod and then I type rs.initiate()
Lab Deploy a Replica Set 1

But at the end when I try to create a user I get the following:Lab Deploy a Replica Set 2

Thanks for helping me out

Step 3. When this node is running, use the mongo shell to connect and initiate your replica set with rs.initiate(). The shell prompt will read PRIMARY when the election is complete.

You are missing to connect mongo shell, after connect you can execute rs.initiate()

do you mean to open up a new Terminal with the button “+” and then it would be Terminal 1 ?
In that new terminal 1 may I create the new user?

No, connect the mongo shell using mongo command, pass the host url and port number,
for ex.:

mongo --port 27001

You can refer the previous lecture that is available above this Lab,

I did what you said and I also saw the video. But then when I try to create the user I get the following :error user

The $db:"test" from the error message indicates that you are trying to create the user in the test database rather than the admin database.

However, this should not produce the error message as creating a user in the test database is valid but unusual. One reason might be that the user already exists. To verify that try to connect using the m103-admin user.

1 Like


I try to connect by typing the command:
mongo --username m103-admin --password --authenticationDatabase admin --host m103-repl --port 27001
but it seems like the admin user does not exist yet.

Yes without creating user you cannot login
How did you login when you ran rs.initiate()
In same session you should create user after switching to admin db and use that userid/pwd for subsequent login
First time you will be connecting with local host exception

Also check syntax to connect a replicaset
Something like below
mongo --host “replica_name/hostname or ip:port” -u -p --authenticationDatabase admin

Hi @Erru_Niffuxo,

Let us know if you are still facing any issues.

Yes, I am still having issues. I try the command mongo --host “m103-repl” -m103-admin -m103-pass --authenticationDatabase admin.
But still the same errors.

Why you are using --host?
And m103-repl is not hostname.It is replicaset name

If you wnat to connect to a node try
mongo --port port_num -m103-admin -m103-pass --authenticationDatabase admin
Assuming here the user m103-admin already created or exists
If you want to connect to replicaset try the syntax i gave in earlier post