Error: couldn't add user: not master

Any ideas why I am getting this error please?

vagrant@m103:~$ mongo admin --host localhost:27000 --eval ’
user: “m103-admin”,
pwd: “m103-pass”,
roles: [
{role: “root”, db: “admin”}

MongoDB shell version v3.6.12
connecting to: mongodb://localhost:27000/admin?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“42fca023-b40d-4042-a6f2-3cac33c7d984”) }
MongoDB server version: 3.6.12
2019-06-22T14:56:56.787+0000 E QUERY [thread1] Error: couldn’t add user: not master :
@(shell eval):2:1

Is this a standalone mongod or a replica set?
As per error you have to run the command on primary
Make sure all instances are up.Check rs.status()
Check if user already exists

show users

I think the server is saying that you are trying to do a write operation on a secondary node, which is forbidden. If you are running a standalone node use

ps -ef | grep mongod

to see if there is any other mongod that could be the primary running in the same replica set. Also, check your conf if you are using

  replSetName: <replica set name>

It’s possible that if a replica set has only one node, it automatically become secondary and not primary. Deleting that line would force the mongod process to act as a standalone and it’s own primary.


Hi @kezieiroha,

Are you still facing this issue?

Please follow the solutions provided by @Ramachandra_37567, @Quang_80634. If you still face the same issue, let me know.


Hi, i was facing the same issue as @kezieiroha, this helped me solve it.
Thank you!

1 Like