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

MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser({user: “m103-admin”, pwd: “m103-pass”, roles: [{role: “root”, db: “admin”}]})
2019-11-14T04:20:09.886+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):1:1

And… :face_with_monocle: ?

its for configuration file lab I cant create the user how to connect mongod on 27000

It’s always good to add some explanation… remember this is a discussion forum :wink:

The error message is telling you that authorisation is enabled and you must first of all login with a user using db.auth(). I suspect that you’ve already created that user so try:
use admin
db.auth("m103-admin", "m103-pass")

1 Like

yes this command showing “1”,
I used below command to connect to mongod
mongo --port 27000 --authenticationDatabase “admin” -u “m103-admin” -p “m103-pass”
it’s getting connected successfully


when I run validate_lab_configuration_file I got below error

Hi @Milind_19368,

Can you please share your config file that you are using to run this mongod instance?

Also, please share the output of ps -ef | grep mongo command.

Meanwhile, I would like you to confirm if you created the user in “admin” database only and if you are able to connect to “m103-admin” user.

Thanks,
Muskan

Hi @Muskan_47318,

please check below output for ps -ef

@Milind_19368 let’s see the commands you used to create the user.

Scroll up inside the terminal to check that you executed use admin before you ran createUser.

yes I have used use admin before create the user

do I delete the user and create it again what is the command to delete the user?

It’s your only user, you can’t delete it if you have authorisation enabled. Let’s see your config file.

storage:
dbPath: “/data/db”
systemLog:
path: “/data/lab1.log”
destination: “file”
replication:
replSetName: M103
net:
bindIp : “127.0.0.1,192.168.103.100”
port: 27000
processManagement:
fork : true
security:
authorization: enabled

I can’t see any problem here. Please delete your last post so that other students don’t get to see this config.

It’s best you redo the lab. Keep your config file and follow these steps:

  1. Shutdown the server:
    use admin
    db.shutdownServer()
  2. Delete all the db files:
    rm -r /data/db/*
    rm /data/lab1.log

Now you can startup the mongod, create the user, and login to mongo like before.

1 Like

Error: couldn’t add user: not master :_getErrorWithCode@src/mongo/shell/utils.js:25:13

And? :arrow_up::arrow_up::arrow_up:

I was talking about your other post with the config settings.

ok I deleted the config file

I didn’t say you should delete the config file. I said you should delete the post where you are showing your config. If it’s not clear, I’m talking about post #14.

Problem solved, Thanks 007_ib,
it’s going to replication node that’s why user not get created, that’s why above error thrown,

rs.initiate()
it’s switched the node to primary then created the user