Mongo - How can I find out what roles the user I am connected as has? How can I assign a user full read-write access?

jononomo picture jononomo · Nov 10, 2014 · Viewed 12.9k times · Source

I have been able to connect to my Mongo instance (which is hosted in the cloud at Compose.io -- it is an "addon" through Heroku) from my MacBook terminal command line.

However, I cannot perform any operations. Commands like "show collections" and "show users" fail with a "not authorized" error.

How can I find out what roles the user I am connected as has? Also, how can I add a user with full read-write permissions? Of course I've tried:

db.createUser({
    user: "accountUser",
    pwd: "password",
    roles: [ "readWrite", "dbAdmin" ]
})

but this command fails with couldn't add user: not authorized on my_db to execute command

Answer

wdberkeley picture wdberkeley · Nov 10, 2014

To view information about the current user, run db.getUser() on the user's database. You'll need to check with your MongoDB provider on how they've set up the security to figure out how to add the correct roles to your users.