Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to authenticate mongodb remotely

I am unable to authenticate mongodb remotely. I'm running MongoDB 3.0.0 provided by the DigitalOcean One-Click installer, and I can't seem to set up authentication properly.

I have 1 database called wbio_production. I followed mongodb docs tutorials as best as I could. When I execute:

> db.auth("siteUserAdmin","MYPASSWORD")
1
> db.getUsers()

The output of that is:

{
    "_id" : "admin.siteUserAdmin",
    "user" : "siteUserAdmin",
    "db" : "admin",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
} 

And when I switch to the wbio_production database and perform the same getUsers():

> use wbio_production
switched to db wbio_production
> db.getUsers()
[
    {
        "_id" : "wbio_production.herokuUser",
        "user" : "herokuUser",
        "db" : "wbio_production",
        "roles" : [
            {
                "role" : "userAdmin",
                "db" : "wbio_production"
            },
            {
                "role" : "readWrite",
                "db" : "wbio_production"
            }
        ]
    }
]

When I fill out the connection form in Robomongo however, it cannot successfully connect to the database. Authorization always fails, however it does successfully connect to the database.

I have tried the following combinations of using the users above:

  1. DB: Admin, User: siteUserAdmin
  2. DB: Admin, User: herokuUser
  3. DB: wbio_production, User: siteUserAdmin
  4. DB: wbio_production, User: herokuUser

All of them wind up with some output coming back in the heroku logs similar:

failed with error 13: "not authorized for query on wbio_production.mongoid_forums_forums"

I have tried reinstalling mongodb, recreating users based off different tutorials, and just trying different peoples explanations. I've spent about 5 hours now looking for a solution to my issue, and now I must turn to SO for your advice. I'm sure this is a simple error on my part that I am not understanding from the docs or something I am continuously missing in the set up.

What must I do to get a secured and functional MongoDB server? Thanks!

like image 278
njny Avatar asked Apr 06 '15 04:04

njny


People also ask

Why is my MongoDB not connecting?

If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.

Why MongoDB compass is not connecting?

This error often occurs when: You provide no hostname or an invalid hostname to the Compass connect dialog. The destination server rejects a connection on an incorrect port. Your MongoDB cluster or server has been shutdown or the server hostname has changed.


1 Answers

You need to configure mongod with its binding so clients can connect remotely.

bind_ip = 0.0.0.0
like image 172
Wylan Osorio Avatar answered Oct 09 '22 12:10

Wylan Osorio