Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication failed error #772

Closed
jswh opened this issue Mar 8, 2016 · 10 comments
Closed

Authentication failed error #772

jswh opened this issue Mar 8, 2016 · 10 comments

Comments

@jswh
Copy link

jswh commented Mar 8, 2016

I am using a remote mongo server with password and username.And the configuration looks like this

'mongodb' => [
        'driver'   => 'mongodb',
        'host'     => ['192.168.1.100'],
        'port'     => 27017,
        'database' => 'database',
        'username' => 'username,
        'password' => 'passed',
        'options'  => []
    ],

I got an "Authentication failed" when using the Moloquent and remove the database in the dsn to fix it.
I am not sure how this error happen, speculating it is the duplicated database selections both in constructor and dsn builder cause this error.

//in constructor
$this->db = $this->connection->selectDatabase($config['database']);
//in dsn
return "mongodb://" . implode(',', $hosts) . "/{$database}";
@jaffar-citytwig
Copy link

I was having same issue and then came here on this thread.
I have done exactly as mentioned above and problem resolved,
But don't know how this error happened.
Can anyone let us know the exact reason and proper solution for this??

@jswh
Copy link
Author

jswh commented Apr 5, 2016

I change the config type to fix this problem.The config may like this

    'mongodb' => [
        'driver'   => 'mongodb',
        'dsn'      => 'mongodb://127.0.0.1:27017',
        'username' => 'username',
        'password' =>  'passwd',
        'database' => 'db',
        'options'  => ['connectTimeoutMS' => 50]
    ],

@jaffar-citytwig

@acedude
Copy link

acedude commented Apr 6, 2016

I can confirm that the solution above works. I'm using the same server with package version 2 in another app, and it works just fine.

@acedude
Copy link

acedude commented Apr 6, 2016

@jswh I found a better solution. Change:

'options' => [
                'db' => 'admin' // sets the authentication database required by mongo 3
            ]

to

'options' => [
                'database' => 'admin' // sets the authentication database required by mongo 3
            ]

@karthikbhatcd
Copy link

@acedude +1

@jswh
Copy link
Author

jswh commented May 27, 2016

There are several solutions, I will close this issue.

@jswh jswh closed this as completed May 27, 2016
@willypuzzle
Copy link

I have this configuration:

'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => '127.0.0.1',
            'port'     => '27017',
            'database' => 'chat',
            'username' => 'chat',
            'password' => 'dfferdfvd234',
            'options' => [
                'database' => 'admin' // sets the authentication database required by mongo 3
            ]
        ],

It gives me 'auth failed' error.
If I comment out username and password fields then it works.
I have the same username and password setted on Moongose with a nodejs server and it connects normally.
I tried @jswh solution but it doesn't work for me.
I have Laravel 5.3 and I'm using "jenssegers/mongodb": "^3.1" updated to today.

@acedude
Copy link

acedude commented Nov 6, 2016

Are you sure it's an issue with the package? Don't you have auth disabled on your server?

@funyug
Copy link

funyug commented Nov 6, 2016

Had the same issue today after running composer update. Commenting out username and password worked.

@sharmahemal
Copy link

sharmahemal commented Apr 25, 2018

yes , i have same issue occurs with authentication mongodb username and password

error: "127.0.0.1:27017: not authorized for query on telesanteclik.users"

in No SQL manager working fine and connect well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants