Laravel-mongodb: Authentication failed. (MongoDB 3.2 and Laravel 5.3)

Created on 20 Sep 2016  路  8Comments  路  Source: jenssegers/laravel-mongodb

[MongoDB\Driver\ExceptionAuthenticationException]
Authentication failed.

Most helpful comment

Its works

Upgrade mongo driver dependence mongodb/mongodb 1.0.3 to 1.0.4 and update database.php
```php
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'database' => env('DB_DATABASE') // sets the authentication database required by mongo 3
]
],

All 8 comments

i actually replaced the database in options array to db

mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'db' => 'admin' // replace "database" to "db"
]
],

Its works

Upgrade mongo driver dependence mongodb/mongodb 1.0.3 to 1.0.4 and update database.php
```php
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'database' => env('DB_DATABASE') // sets the authentication database required by mongo 3
]
],

It works...thanks a lot @uriel2707

i want to connect to remote server from my local machine but i am having Authentication failed error .

i am able to connect to my local machine correctly but i cant connect to the remote server

from my local machine i can connect to the remote host via ssh and specify the user and the pwd .

any idea on how to connect to a remote sever please thanks in advance

'mongodb2' => [
'driver' => 'mongodb',
'host' => env('DB2_HOST', 'xx.xxx.xx.xx'),
'port' => env('DB2_PORT', 27017),
'database' => env('DB2_DATABASE','admin'),
'username' => env('DB2_USERNAME',''),
'password' => env('DB2_PASSWORD',''),
'use_mongo_id' => false,
'options' => [
'database' => 'admin',
]
]

@ssallah why are you using mongodb2 as the key? also use_mongo_id is not necessary

'options' => [
'authSource' => 'admin',
]

use admin
db.createUser({user: "admin", pwd: "123456", roles:["root"]})

This error is exist .. I am able to connect through client but but not able to connect laravel mongodb driver .. authentication error is coming

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phuocduy1988 picture phuocduy1988  路  3Comments

BlakeGardner picture BlakeGardner  路  3Comments

ghost picture ghost  路  3Comments

kschethan picture kschethan  路  3Comments

HassanIbrahim picture HassanIbrahim  路  3Comments