Search code examples
databasemongodbrolesmongodb-authentication

No user in mongodb with admin privileges - how can create an user with admin privileges?


At first there is no authentication in mongodb, so I created one for one database with readWrite role.

Now I want to create more users for other databases but as this user doesn't have the privileges to create other users I'm stuck.


Solution

  • The documentation clearly says:

    With access control enabled, ensure you have a user with userAdmin or userAdminAnyDatabase role in the admin database. This user can administrate user and roles such as: create users, grant or revoke roles from users, and create or modify customs roles.

    If you haven't created such user, you cannot create it now with authentication and access rights enabled. I gues you need to restart the MongoDB server without authentication enabled, create that admin user, and restart the MongoDB server again with authentication enabled.

    I highly recommend you read to complete documentation how to enable authentication first to understand the complete concept, before you follow it step by step. Otherwise it might be confusing and creating such state you are currently locked in and cannot continue with all actions.