I'm more familiar with MySQL, but in my new workplace, I have to look after a MongoDB database (MongoDB 4.2.18 with Mongosh 1.1.9 running on Ubuntu 18.04.6 -- yes, it's old; upgrading is a problem for another day). I don't know anything about MongoDB. Unfortunately, the person who created it has left and left behind no documentation. Now, I need to look after it.

What I have is a username and a password. With that, I can login like so:

mongosh --port 27017 --authenticationDatabase "admin" -u "XXX" -p

I can list all of the databases by doing show databases. But, I can't execute the command show users:

admin> show users
MongoServerError: not authorized on admin to execute command { usersInfo: 1, lsid: { id: UUID("b2c4e061-1b54-4b27-bdf2-bef330b38b4d") }, $db: "admin" }

I then tried to get a list of users. And I think this is the command to do it:

admin> show collections
admin> db.system.users.find().pretty ()
MongoServerError: not authorized on admin to execute command { find: "system.users", filter: {}, lsid: { id: UUID("1801ce09-5c09-44eb-9b04-86eb35817eaa") }, $db: "admin" }

Together, this feels like my account isn't an administrator's account. Would this be correct?

If so, is it possible to create a new account with full administator's privileges? I have sudo access on the host machine. If so, how would I do that?

Thank you!


2 Answers 2


Edit your configuration file (typically /etc/mongod.conf) to this

   authorization: disabled

As precaution in order to prevent unauthorized connections, you may also set

   port: 55555
   bindIp: localhost

Then restart the mongod service. Now, you can connect with

mongosh --port 55555

and you have all privileges on the database. Change the password and/or credentials of user XXX or create a new admin user. You can check existing credential usersInfo command.

     createUser: "administrator",
     pwd: "secret"
     roles: [
       { role: "root", db: "admin" }

Revert configuration changes and restart mongod again.

  • Ah! That worked! Thank you! So, my guess was correct. The previous developer who developed the system in-house and has since left, never left behind the administrator's password... Oh well...
    – Ray
    Commented Sep 15, 2023 at 16:01

Yes it's administrator account... You just need to change to admin DB, where user information is. So, type "use admin" + enter. You can always check on what DB you are just type "db" + enter.

With your mongodump problem. Parameters --db= and/or --authenticationDatabase= will solve your problem (depending your problem). Use mongodump --help

What to come to question how to see if your role is admin, use db.getUser("admin"). Check here!

  • Thanks for the answer! In the example above, I have typed use admin. (I didn't show it, but the prompt has changed to admin>.) I also used the same login credentials to run mongodump of the admin database, and it failed (other databases were ok). Despite this, you reckon this is an administrator's account?
    – Ray
    Commented Sep 14, 2023 at 14:35
  • "Despite this, you reckon this is an administrator's account?" - I would have ask the same question. How can you know this? Commented Sep 14, 2023 at 19:54
  • Check my edit to the answer!
    – JJussi
    Commented Sep 15, 2023 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.