mongodbで ERROR: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '127.0.0.1:27017'] {"exception":"[object] (MongoDB¥¥Driver¥¥Exception¥¥ConnectionTimeoutException(code: 13053): mongodb
docker上で、php+laravelコンテナと、mongodbコンテナをセットしてシステム構築した際に出たエラー
■エラー内容
[2020-06-14 11:43:40] local.ERROR: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on 127.0.0.1:27017 ] { exception : [object] (MongoDB¥¥Driver¥¥Exception¥¥ConnectionTimeoutException(code: 13053): No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on 127.0.0.1:27017 ] at ./vendor/mongodb/mongodb/src/Database.php:341)
[stacktrace]
#0 ./vendor/mongodb/mongodb/src/Database.php(341): MongoDB¥¥Driver¥¥Manager->selectServer(Object(MongoDB¥¥Driver¥¥ReadPreference))
#1 ./vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php(44): MongoDB¥¥Database->listCollections()
#2 ./vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Schema/Builder.php(58): Jenssegers¥¥Mongodb¥¥Schema¥¥Builder->hasCollection( data_types )
#3 ./vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(223): Jenssegers¥¥Mongodb¥¥Schema¥¥Builder->hasTable( data_types )
#4 ./vendor/tcg/voyager/src/VoyagerServiceProvider.php(260): Illuminate¥¥Support¥¥Facades¥¥Facade::__callStatic( hasTable Array)
#5 ./vendor/tcg/voyager/src/VoyagerServiceProvider.php(107): TCG¥¥Voyager¥¥VoyagerServiceProvider->registerGates()
#6 [internal function]: TCG¥¥Voyager¥¥VoyagerServiceProvider->boot(Object(Illuminate¥¥Routing¥¥Router) Object(Illuminate¥¥Events¥¥Dispatcher))
#7 ./vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array Array)
#8 ./vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate¥¥Container¥¥BoundMethod::Illuminate¥¥Container¥¥{clos
■対応
.envでの、DB_HOSTが間違っていた
mongodb用に用意したコンテナ名を指定する
DB_HOST=mongo
に修正