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}";
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??
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
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.
@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
]
@acedude +1
There are several solutions, I will close this issue.
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.
Are you sure it's an issue with the package? Don't you have auth disabled on your server?
Had the same issue today after running composer update. Commenting out username and password worked.
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
Most helpful comment
@jswh I found a better solution. Change:
to