I had a similar problem with mongo 3.2:
Error: Failed to add user: not master:
When trying to create a new user with a root role.
I used only a local copy of mongo.
In my mongod.conf file, I had the following without comment:
replication: replSetName: <node name>
Commenting on this, restart and fix the problem. I think the mongo thought it was part of a replica set, and was embarrassed by those who were Master.
Edit:
I also found that if you are trying to set up a replication set and get the above error, run:
rs.initiate ()
This will start the replication set and set the current node as PRIMARY.
Log out and then log in and you will see:
PRIMARY>
Now create users as needed.
source share