Mongo version: 3.2.11

I spun up a mongoDB droplet with DigitalOcean so that I could have a database connected to my little game. However, complications after complications have arisen. I am connecting to the droplet through PuTTY and was previously able to invoke "mongo" then type "show dbs" to see all the current databases.

I had been altering the /etc/mongod.conf file to allow remote connecting, and since then - any command that I invoke spits back an error message:

Just through a simple show dbs - I get this.

> show dbs
2016-12-28T00:12:26.655+0000 E QUERY    [thread1] Error: listDatabases failed:{
        "ok" : 0,
        "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
        "code" : 13
} :

I'm so confused as to why this is and I've been scouring the internet to find anything that could possibly resolve this.

PS: I had altered the /etc/mongod.conf file by uncommenting security and adding authorization: 'enabled' to it, as well as commenting out bindIp: under net.

  • It might be helpful to include how exactly you "had been altering the /etc/mongod.conf file to allow remote connecting".
    – mustaccio
    Commented Dec 29, 2016 at 3:22
  • I've now added that as a PS in the main post. Commented Dec 29, 2016 at 3:58

3 Answers 3


Let's try this:

Connect to your DO droplet.

In your /etc/mongod.conf, comment out 'security' and restore bindIp to value

Restart your mongod instance.

Connect to mongo (at this point without security).

Create you admin user in mongo with something like this:

use admin
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]

Make sure the user was successfully created.

Go back to your /etc/mongod.conf. Set your bindIp value as:,YOUR_DO_DROPLET_IP (no spaces between).

Uncomment 'security', keep 'authentication' commented out, add below it 'authorization: enabled'

Restart your server's mongod instance.

Connect to mongod remotely by using:

mongo YOUR_DO_DROPLET_IP -u myUserAdmin -p --authenticationDatabase admin

References: MongoDB Authentication Enabling MongoDB Authentication

  • 2
    I'm connected as "super" and I have the role "userAdminAnyDatabase" on the admin database. I still receive that error when I use adminCommand (setFeatureCompatibilityVersion) on MongoDB v 3.4 (I want to upgratde to 3.6)
    – Alex 75
    Commented Mar 19, 2018 at 12:31
  • Tried, having same error during createUser command Commented Sep 11, 2019 at 13:57

I followed these steps on Centos 7 for MongoDB 4.2. (Remote user)

Update mongod.conf file

vi /etc/mongod.conf
     port: 27017
     authorization: enabled

Start MongoDB service demon

systemctl start mongod

Open MongoDB shell


Execute this command on the shell

use admin
    user: 'admin',
    pwd: 'YouPassforUser',
    roles: [ { role: 'root', db: 'admin' } ]

Remote root user has been created. Now you can test this database connection by using any MongoDB GUI tool from your dev machine. Like Robo 3T


userAdminAnyDatabase is still not enough for granting the admin privilege. Use the root role for having the real admin privilege.

To add new permission you can update the role.

use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])

For reference: https://stackoverflow.com/a/29472184/20739269

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.