Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No suitable servers found (serverSelectionTryOnce set): [Failed to resolve 'mongodb'] #2231

Closed
KolyaSlisarenko opened this issue Apr 8, 2021 · 1 comment

Comments

@KolyaSlisarenko
Copy link

  • Laravel-mongodb Version: 3.8.3
  • PHP Version: 7.4.15
  • Laravel version: 8.27.0

Description:

After installation steps, it's impossible to get rows from the collection

config/database.php

"driver" => "mongodb",
"host" => "mongodb",
"port" => "27017",
"database" => "cinema",
"username" => "slisarenko",
"password" => "password",
"options" => [
"database": "admin"
]

docker-compose.yml
...
mongodb:
container_name: mongodb
volumes:
- mongodbdata:/data/db
image: mongo
ports:
- 27017:27017
logging:
driver: none
...

Logs:
[2021-04-08 17:50:53] local.ERROR: No suitable servers found (serverSelectionTryOnce set): [Failed to resolve 'mongodb'] {"exception":"[object] (MongoDB\Driver\Exception\ConnectionTimeoutException(code: 13053): No suitable servers found (serverSelectionTryOnce set): [Failed to resolve 'mongodb'] at /var/www/vendor/mongodb/mongodb/src/functions.php:431)
[stacktrace]
#0 /var/www/vendor/mongodb/mongodb/src/functions.php(431): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
#1 /var/www/vendor/mongodb/mongodb/src/Collection.php(651): MongoDB\select_server(Object(MongoDB\Driver\Manager), Array)
#2 [internal function]: MongoDB\Collection->find(Array, Array)
#3 /var/www/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Collection.php(42): call_user_func_array(Array, Array)
#4 /var/www/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Builder.php(399): Jenssegers\Mongodb\Collection->__call('find', Array)
#5 /var/www/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Builder.php(192): Jenssegers\Mongodb\Query\Builder->getFresh(Array)
#6 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(571): Jenssegers\Mongodb\Query\Builder->get(Array)
#7 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(555): Illuminate\Database\Eloquent\Builder->getModels(Array)
#8 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(476): Illuminate\Database\Eloquent\Builder->get(Array)
#9 /var/www/routes/web.php(25): Illuminate\Database\Eloquent\Model::all()
#10 /var/www/vendor/laravel/framework/src/Illuminate/Routing/RouteFileRegistrar.php(35): require('/var/www/routes...')
#11 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(425): Illuminate\Routing\RouteFileRegistrar->register('/var/www/routes...')
#12 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(382): Illuminate\Routing\Router->loadRoutes('/var/www/routes...')
#13 /var/www/vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php(135): Illuminate\Routing\Router->group(Array, '/var/www/routes...')
#14 /var/www/app/Providers/RouteServiceProvider.php(48): Illuminate\Routing\RouteRegistrar->group('/var/www/routes...')
#15 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Providers\RouteServiceProvider->App\Providers\{closure}()
#16 /var/www/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#17 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(81): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#18 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure), Object(Closure))
#19 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(610): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Object(Closure), Array, NULL)
#20 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(120): Illuminate\Container\Container->call(Object(Closure))
#21 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(45): Illuminate\Foundation\Support\Providers\RouteServiceProvider->loadRoutes()
#22 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Foundation\Support\Providers\RouteServiceProvider->Illuminate\Foundation\Support\Providers\{closure}()
#23 /var/www/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#24 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(81): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#25 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure), Object(Closure))
#26 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(610): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Object(Closure), Array, NULL)
#27 /var/www/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php(113): Illuminate\Container\Container->call(Object(Closure))
#28 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(902): Illuminate\Support\ServiceProvider->callBootedCallbacks()
#29 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(880): Illuminate\Foundation\Application->bootProvider(Object(App\Providers\RouteServiceProvider))
#30 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(App\Providers\RouteServiceProvider), 27)
#31 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(881): array_walk(Array, Object(Closure))
#32 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#33 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(237): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#34 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(152): Illuminate\Foundation\Application->bootstrapWith(Array)
#35 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(136): Illuminate\Foundation\Http\Kernel->bootstrap()
#36 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#37 /var/www/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#38 {main}
"}

@divine
Copy link
Contributor

divine commented Apr 8, 2021

Hello,

Looks like the error not related to this library for sure.

Try changing "host" => "mongodb", to "host" => "localhost", because mongodb host doesn't resolve withing your environment.

Thanks!

@divine divine closed this as completed Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants