Lab - Initiate a Replica Set Locally -- couldn't add user: there are no users authenticated


I followed all steps in “Lab - Initiate a Replica Set Locally”. Until I reached initiating the replica set:


And it worked and became Primary> … then I did

use admin

Then when I was creating a user:


I got the error message:

[thread1] Error: couldn’t add user: there are no users authenticated :

I tried to start mongod in both ways:

mongod -f mongod-repl-1.conf


mongod -f mongod-repl-1.conf --auth

I was sure that I killed the previous mongod in the process. So what did I do wrong?

1 Like

Please check if user already exists
connect to admin

db.auth(“m103-admin”, “m103-pass”)---->should return 1

1 Like

MongoDB Enterprise m103-repl:PRIMARY> db.system.users.find().pretty()

Error: error: {
“operationTime” : Timestamp(1561726111, 1),
“ok” : 0,
“errmsg” : “there are no users authenticated”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1561726111, 1),
“signature” : {
“hash” : BinData(0,“wqe9u5UdZfCC0yE0j4HVu1Vi0p0=”),
“keyId” : NumberLong(“6707315010139324417”)

Okay I figured out that I have to do this

use admin

1 Like

Two ways to authenticate
One is above and other is to connect to mongod with the newly created user which i see you already did in other post

If the first to connect to the server, you must to create the user root
user: “myUserAdmin”,
pwd: “abc123”,
roles: [ { role: “root”, db: “admin” } ]