When I try to add a new user using the db.createUser command, I get the error:

2015-03-05T20: 29: 10.639 + 0200 E QUERY
Error: couldn't add user: no role userAdminAnyDatabase @ test23s at Error (<anonymous>) at DB.createUser (src / mongo / shell / db.js: 1066: 11) at (shell): 1: 4 at src /mongo/shell/db.js:1066

To add I use the command:

db.createUser( { user: "admin94", pwd: "14336546545", roles: [ {role: "userAdminAnyDatabase", db: "test23s"}] } ) 

    1 answer 1

     Error: couldn't add user: No role named userAdminAnyDatabase@test23s 

    This

    Find out what roles you have to start with: db.getRoles()

    Or try this:

     db.createUser( { user: "admin94", pwd: "14336546545", roles: [ { role: "readWrite", db: "test23s" } ] } ) 

     db.createRole( { role: "mongostatRole", privileges: [ { resource: { cluster: true }, actions: [ "serverStatus" ] } ], roles: [] } ) 
    • >> db.getRoles ()> [] - Jeix
    • Well, that's the answer, you're trying to use a role that doesn't exist. Here is a detailed off mang on how to create a role: docs.mongodb.org/manual/tutorial/define-roles Ie something like this can be done Complemented answer - deterok