Wednesday, 31 August 2016

How to create superuser in MongoDB?

I am using mongoDB version 3.2

mongoDB has defined basic in built roles such as -
1.read
2.readWrite
3.userAdmin
4.dbOwner
5.dbAdmin
6.clusterAdmin
7.readWriteAnyDatabse
8.readAnyDatabase
8.userAdminAnyDatabase 
9.restore 
10.root 
etc.

For "superuser" I mean user must have right to read,write.admin option to any database in mongod instance server.

No 10 "role option "root" mentioned above is superuser.

root = readWriteAnyDatabase, + dbAdminAnyDatabase + userAdminAnyDatabase+clusterAdmin  + restore

Create user as below ->

db.createUser({user:"superAdmin",pwd:"super123",roles:["root"]});

It has db scope limited to admin db.
So connect to admin db and then authenticate first.
Then you can access any db you want.

No comments:

Post a Comment