Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '127 .0.0.1:27017']

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

like image 581
ehsan asarzadeh Avatar asked Jun 29 '20 14:06

ehsan asarzadeh


1 Answers

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

like image 144
Erfan Ghezelbash Avatar answered Oct 04 '22 14:10

Erfan Ghezelbash