I want to use MongoDB for my Laravel project in Xampp but when I use the database it shows this error, I've checked the config many times and searched for it but I found no suitable answer, any solutions?
error:
No suitable servers found (serverSelectionTryOnce
set): [connection refused calling ismaster on '127.0.0.1:27017']
.env file:
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=mongotest
DB_USERNAME=
DB_PASSWORD=
config/database.php file:
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'options' => [
// here you can pass more settings to the Mongo Driver Manager
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
'database' => env('DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+
],
],
i'm using Xampp, Laravel 6, PHP 7.4, mongodb 1.7.4
I think you didn't run mongodb service in your OS. I think you can find a good guide here:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#run-mongodb-community-edition-as-a-windows-service
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With