Description
Exception description:
Fatal error: Uncaught TypeError: MongoDB\select_server(): Return value must be of type MongoDB\Driver\Server, null returned in C:\XXX\vendor\mongodb\mongodb\src\functions.php:535
Stack trace:
#0 C:\XXX\vendor\mongodb\mongodb\src\Database.php(273): MongoDB\select_server(Object(MongoDB\Driver\Manager), Array)
#1 C:\XXX\shared\connection.php(6): MongoDB\Database->createCollection('test')
#2 C:\XXX\index.php(11): require_once('C:\\XXX\\...')
#3 {main} thrown in C:\XXX\vendor\mongodb\mongodb\src\functions.php on line 535
I've all drivers installed, configured as well as php module enabled etc.
The code i'm trying to execute:
$client = new MongoDB\Client('mongodb+srv://XXXX/admin?authSource=YYYY&replicaSet=ZZZZ&readPreference=primary&ssl=true');
$collection = $client->CyberNightly;
$a = $collection->createCollection("test");
My composer.json
{
"require": {
"mongodb/mongodb": "^1.13",
"jenssegers/mongodb": "^v3.5.0",
"ext-mongodb": "*"
}
,
"require-dev": {
"roave/security-advisories": "dev-latest"
}
}
Am i making some mistakes? Why this happens? I've generated the connection string using Atlas since it provides you the exact string depending from the version of the driver. (XXX,YYY,ZZZ are to obscure some obv infos).
UPDATE: I also managed to deep dive in the library and found that when i call createCollection method he wants to pass to select_server function the Manager object (Database.php) and for some reason it's empty so obviously it gives problem later on... Also i watched where the libs create that object and the parameters are passed all correctly but after the creation of the object it's empty...
I've also made a post on Stack Overflow and run php --ri as suggested:
Link: https://stackoverflow.com/questions/74488299/phpmongodb-return-value-must-be-of-type-mongodb-driver-server-null-returned