I'm using jenssegers/laravel-mongodb MongoDB Jenssegers
I'm running into an issue where I can't seem to connect using the framework, but using a simple test script, I can connect fine.
The simple connection script I wrote:
<?php
$manager = new MongoDB\Driver\Manager("mongodb://user:password@cluster0-shard-00-00-reodz.mongodb.net:27017,cluster0-shard-00-01-reodz.mongodb.net:27017,cluster0-shard-00-02-reodz.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin");//ssl=true
$command = new \MongoDB\Driver\Command(["ping" => 1]);
$cursor = $manager->executeCommand("admin", $command);
$reply = $cursor->toArray()[0];
var_dump($reply);
When I run that, I get
["ok"]=> int(1)
Which is what I expect and is all good. I setup my config/database.php file with the same connection string, this is my config/database.php file:
return [
'default' => env('DB_CONNECTION','mongodb'),
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_DSN','mongodb://user:password@cluster0-shard-00-00-reodz.mongodb.net:27017,cluster0-shard-00-01-reodz.mongodb.net:27017,cluster0-shard-00-02-reodz.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin'),
'database' => env('DB_DATABASE'),
]
]
];
The .env file:
APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC
#DB_CONNECTION=mongodb
#DB_HOST="cluster0-shard-00-00-reodz.mongodb.net"
#DB_PORT=27017
DB_DATABASE="test"
#DB_USERNAME="user"
#DB_PASSWORD="password"
CACHE_DRIVER=file
QUEUE_DRIVER=sync
When I access a route that I've associated with MongoDB, I'm getting:
(1/1) ConnectionTimeoutException No suitable servers found (
serverSelectionTryOnce
set): [Failed to resolve 'user:password@cluster0-shard-00-00-reodz.mongodb.net:27017,cluster0-shard-00-01-reodz.mongodb.net:27017,cluster0-shard-00-02-reodz.mongodb.net:27017/test?ssl=true&replicaset=cluster0-shard-0&authsource=admin']
I would assume the problem is localized to my database.php file or my .env file, does anyone see an error? If the test.php can connect and return the ping, shouldn't Lumen be good to go?
Thanks D