HiveBrain v1.2.0
Get Started
← Back to all entries
debugMajor

Mongo Create a user as admin for any database raise an error

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
erroradmincreateusermongoanydatabaseforraise

Problem

I am trying to create a simple user with the rights permission to access to any database and can do any actions. When I trying to execute the createUser command I got this error:

db.createUser({ user: "mongoadmin" , pwd: "mongoadmin", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})
2015-08-20T17:09:42.300+0000 E QUERY    Error: couldn't add user: No role named userAdminAnyDatabase@new_vehicles_catalog


The problem above only happen when I enable the auth configuration and I need it.

So, How do I create an user with admin permission for any database. I want it because I configured my mongo services to uses authentication connection. If I want to execute a dump of my data I have to use this authentication parameters.

Please any help?

Using mongo version 3.0.5.

the service is on Amazon Linux AMI 2015.03 (HVM), SSD Volume Type - ami-1ecae776

Solution

The '...AnyDatabase' roles should be added to the admin database for the user:

use admin
db.createUser({ user: "mongoadmin" , pwd: "mongoadmin", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})


Any database:

  • Database User Roles



  • Database Administration Roles



Admin database:

  • Cluster Administration Roles



  • Backup and Restoration Roles



  • All-Database Roles



Extra: To give different roles on different database and admin:

db.createUser({user:"replSetManager",pwd:"password",roles:[{role:"clusterManager",db:"admin"},{role:"dbOwner", db:"adminsblog"},{role:"readWrite", db:"departmentblog"},{role:"read", db:"otherblog"}]})

Code Snippets

use admin
db.createUser({ user: "mongoadmin" , pwd: "mongoadmin", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})
db.createUser({user:"replSetManager",pwd:"password",roles:[{role:"clusterManager",db:"admin"},{role:"dbOwner", db:"adminsblog"},{role:"readWrite", db:"departmentblog"},{role:"read", db:"otherblog"}]})

Context

StackExchange Database Administrators Q#111727, answer score: 41

Revisions (0)

No revisions yet.