Reputation: 388
I created an admin user on a Mongo 4.4 instance (Ubuntu)
db.createUser(
{
user: "admin",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
Then, I tried to rs.initiate()
and it told me I am not "master". I read this SO thread where people suggest that I do db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])
, but it doesn't work!
It gives me the following error:
uncaught exception: Error: not master :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.grantRolesToUser@src/mongo/shell/db.js:1613:15
@(shell):1:1
Do I have to uninstall MongoDB, reinstall, then create the root user, and then create the admin user?
Upvotes: 0
Views: 605
Reputation: 14520
Your node can only be "not master" if it's already in a replica set. You can only initiate a replica set once and so you shouldn't be trying to initiate it again, it's already initiated.
Upvotes: 1