3

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
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:761:19
shellHelper@src/mongo/shell/utils.js:651:15
@(shellhelp2):1:1

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: 127.0.0.1 under net.

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

Let's try this:

Connect to your DO droplet.

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

Restart your mongod instance.

Connect to mongo (at this point without security).

Create you admin user in mongo with something like this:

use admin
db.createUser(
  {
    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: 127.0.0.1,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 Mar 19 '18 at 12:31
  • Tried, having same error during createUser command – chiragchavda.ks Sep 11 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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