laravelmongodbmongodb-atlasjenssegers-mongodb

Laravel 5.7 mongodb atlas connection problem using jenssegers/mongodb


I want to connect my laravel 5.7 application(I used the 3.4 version of jenssegers/mongodb) with a mongodb in atlas, I tried in localhost(I isntalled the mongo extension) and everything is ok but with atlas i got an error message:

Failed to parse MongoDB URI: 'mongodb://root%3Acluster0.xxx.mongodb.net%3A27017%2Fhddatabase%3FretryWrites%3Dtrue%26w%3Dmajority'. Invalid host string in URI.

My env file:

DB_CONNECTION=mongodb
DB_DSN="mongodb://root:password@cluster0.xxx.mongodb.net:27017/hddatabase?retryWrites=true&w=majority"
DB_DATABASE=hddatabase

My database config:

'mongodb' => [
    'driver'   => 'mongodb',
    'dsn' => env('DB_DSN'),
    'database' => env('DB_DATABASE'),
],

Solution

  • Even with the 'srv' format I'm getting the same error, The problem is that I'm using the version 3.4.0 of jenssegers/mongodb, I upgraded to version 3.4.6 and used the 'srv' format and problem is solved now !