Reputation: 248
I am trying to create user for my mongo database.
Using MongoDB Query: db.createUser({user: 'administrator', pwd: '1234567890', roles: ['root']})
2019-01-29T11:31:32.521+0530 E QUERY [js] Error: couldn't add user: No role named root@test :
mongod.config
there is no file in /etc/mongod.config
Upvotes: 3
Views: 14004
Reputation: 538
Instead of "root" provide readWrite access to the user:
db.createUser({user: 'userName',pwd: 'somePassword',roles: [{ role: 'readWrite', db: 'databaseName'}]})
Upvotes: 0
Reputation: 471
I had the same issue. You have to switch to a database on your mongo server that actually has the role root
because it's saying that the database test
, which is selected when you open a MongoDB shell, doesn't have the role root
. just try use admin
to switch to the admin database and then try db.createUser({ user: "mongoadmin" , pwd: "mongoadmin", roles: ["root"]})
, like you posted in the question. That solved my issue.
Upvotes: 6
Reputation: 2773
Try the following:
db.createUser({ user:"userName",
pwd:"passWord",
roles:[ { role:"readWrite",
db:"dataBaseName"
} ],
mechanisms:[ "SCRAM-SHA-1"]
})
Learn more about mechanisms:[ "SCRAM-SHA-1"]
at https://docs.mongodb.com/manual/core/security-scram/
Upvotes: 8