Did you setup the authentication on the mongo side?
https://docs.mongodb.org/manual/tutorial/enable-authentication/
By default, mongo does not have authentication enabled.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I am thinking to create a collection and insert records to my mongodb when the data is posted to my controller. I have installed jenssegers/laravel-mongodb
In my controller I am using this code bit below.
DB::connection('mongodb')->collection('accounts')->insert($insRow);
In my config/database.php
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'mydb'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'password'),
'options' => [
'db' => 'admin' // sets the authentication database required by mongo 3
]
],
When I ran it, I got an error message saying: AuthenticationException in InsertMany.php line 116: auth failed
Thanks in advance for your help.
Please or to participate in this conversation.