0

I would like to Convert a Standalone to a Replica Set. First step of the procedure mentions to Shut down the standalone mongod instance. Actually the db.shutdownServer() command throws following error: shutdownServer failed: not authorized on admin to execute command. The Built-in Role hostManager should authorized this command. So I tried: db.grantRolesToUser("lala", [{role: "hostManager", db: "myDB"}]) which therefore throws Error: not authorized on admin to execute command. I am using MongoDB shell version: 3.0.5 with a user which has the roles: dbOwner, userAdmin, readWrite. Another approach was to use: db.createUser({user: "hello", pwd: "world", roles: [{role: "hostManager", db: "myDB"}]}) which throws Error: couldn't add user: No role named hostManager@myDB. I really don't get the point how to just shut down.

Senju
  • 435
  • 2
  • 5
  • 20

2 Answers2

2

When Mongod instance is opened with --auth option, it means that your datbase is authenticated. However connection to db is established without any authentication, but you are unable to perform any operation as it throws the error in your description since you are not authenticated. Now switch to authenticated db and then perform authentication using

db.auth( username, password )

Now you may be authorized to perform authorized operations on the db.Try shutdown server now

TharunRaja
  • 707
  • 7
  • 28
2

try this:

db.updateUser("root",{roles:[{"role" : "userAdminAnyDatabase","db" : "admin"},{"role" : "dbOwner","db" : "admin"},{"role" : "clusterAdmin", "db": "admin"}]})

just use your username instead of "root".

archerLj
  • 199
  • 1
  • 2
  • 14