Laravel-mongodb: No suitable servers found

Created on 11 Dec 2018  路  8Comments  路  Source: jenssegers/laravel-mongodb

When I run the ConnectionTest, it succesfully connects to the database (and I can connect in Robo 3T as well), but one of the tests fails and gives me this. The same error message appears when I try to run "artisan migrate".

1) Tests\Unit\MongoConnectionTest::testQueryLog MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found ('serverSelectionTryOnce' set): [connection refused calling ismaster on 'localhost:27017']

I am using a fresh installation of Laravel, and the only things I have done is following your guide. If it matters, I am using Docker and Vessel.

I thought it would be a connection issue, but since I can connect, it doesn't make much sense to me. I have read similar, older threads with the same error, but I can't find a solution.

question

Most helpful comment

  1. Ping in container app host mongo
  2. Value of DB_HOST must be mongo if ping was successful

All 8 comments

Descibe this moment, please.

  1. What command do you run?
  2. Docker and Docker-compose?
  1. Just ran 'php test' in the example, but same error comes when trying to run 'php artisan migrate' ex.
  2. Docker-compose below.

version: '2' services: app: build: context: ./docker/app dockerfile: Dockerfile image: vessel/app ports: - "${APP_PORT}:80" environment: CONTAINER_ENV: "${APP_ENV}" XDEBUG_HOST: "${XDEBUG_HOST}" WWWUSER: "${WWWUSER}" volumes: - .:/var/www/html networks: - vessel node: build: context: ./docker/node dockerfile: Dockerfile args: uid: "${WWWUSER}" image: vessel/node user: node volumes: - .:/var/www/html networks: - vessel mongo: image: mongo restart: always environment: MONGO_INITDB_ROOT_USERNAME: "${DB_USERNAME}" MONGO_INITDB_ROOT_PASSWORD: "${DB_PASSWORD}" ports: - 27017:27017 networks: - vessel redis: image: redis:alpine volumes: - vesselredis:/data networks: - vessel networks: vessel: driver: "bridge" volumes: vesselredis: driver: "local"

  1. Ping in container app host mongo
  2. Value of DB_HOST must be mongo if ping was successful

Im getting the same... was working fine until I created about 700K Jobs to do inserts that I ran on 10 workers... after about 400K ... then DB hung... now even after a docker-compose down & up -d... container stays up but get the error message
MongoDB/Driver/Exception/ConnectionTimeoutException with message 'No suitable servers found ('serverSelectionTryOnce' set): [connection refused calling ismaster on 'mongodb:27017']'

Any resolution?

Im getting the same... was working fine until I created about 700K Jobs to do inserts that I ran on 10 workers... after about 400K ... then DB hung... now even after a docker-compose down & up -d... container stays up but get the error message
MongoDB/Driver/Exception/ConnectionTimeoutException with message 'No suitable servers found ('serverSelectionTryOnce' set): [connection refused calling ismaster on 'mongodb:27017']'

Any resolution?

I'm facing the same problems, and sometimes even the connection stops to work, this library if MongoDB is so unstable, we're starting considered to move to Redis or another NoSQL database, MongoDB in future it'll be no more supported for php anyway.

I ended up wiping that DB and restoring from a backup. I never figured out of my DB got corrupted or if there were just too many write operations queued up that were taking forever making mongo pretty much unresponsive. I agree that lack of support and good tools for mongo admin make it a less desirable choice. We're considering moving to mysql and leveraging their newer JSON support for our unstructured data requirements.

Im getting the same... was working fine until I created about 700K Jobs to do inserts that I ran on 10 workers... after about 400K ... then DB hung... now even after a docker-compose down & up -d... container stays up but get the error message
MongoDB/Driver/Exception/ConnectionTimeoutException with message 'No suitable servers found ('serverSelectionTryOnce' set): [connection refused calling ismaster on 'mongodb:27017']'
Any resolution?

I'm facing the same problems, and sometimes even the connection stops to work, this library if MongoDB is so unstable, we're starting considered to move to Redis or another NoSQL database, MongoDB in future it'll be no more supported for php anyway.

So, in the end, we're starting doing this process, MongoDB it was already not so good database (at least I have horribles experiences with it using C++, Python and now in PHP), we'll move everything to Redis and we give up of mongo and this library also, and probably after 2 years it'll be deprecated of PHP for sure and our project was made to have stability and we don't want to use things that made it more unstable.

Thank you guys and good luck.

Hi I am getting this error
image
I had tried
'mongodb' => [ 'driver' => 'mongodb+srv', 'host' => [ 'mongoUser:[email protected]:27017/payment?retryWrites=true&w=majority', ], 'port' => 27017, 'database' => env('DB_DATABASE'), 'username' => env('DB_USERNAME'), 'password' => env('DB_PASSWORD'), 'options' => [ 'ssl' => true, 'replicaSet' => 'replicaSetName', ], ],
and

Also I tried dsn in it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomartailored picture tomartailored  路  3Comments

HassanIbrahim picture HassanIbrahim  路  3Comments

ricardofontanelli picture ricardofontanelli  路  3Comments

yupangestu picture yupangestu  路  3Comments

imrannazirbhat picture imrannazirbhat  路  3Comments