Hello, I am trying to connect via the PHP driver. I have followed the installation procedures from MongoDB’s PHP Driver documentation regarding pecl install for the extension and composer install of mongodb into the root directory.
I have used the below code to launch the php driver and establish the connection to the database (note that I did change the inputs for db, pass, and cluster in the actual code).
<?php
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
$client = new MongoDB\Client(
'mongodb+srv://<my-database>:<my-password>@<my-cluster>.lkffbtl.mongodb.net/?retryWrites=true&w=majority');
var_dump( $client );
However, when I run this, I receive the following fatal error:
Fatal error : Uncaught Error: Class ‘MongoDB\Driver\Manager’ not found in /home3/coradase/public_html/cora-staging/wp-content/plugins/MongoDB/vendor/mongodb/mongodb/src/Client.php:124 Stack trace: #0 /home3/coradase/public_html/cora-staging/wp-content/plugins/MongoDB/conf.php(6): MongoDB\Client->__construct(‘mongodb+srv://c…’) #1 /home3/coradase/public_html/cora-staging/wp-content/plugins/MongoDB/mongodb.php(28): require_once(‘/home3/coradase…’) #2 /home3/coradase/public_html/cora-staging/wp-includes/class-wp-hook.php(307): cora_mongodb_admin_page(‘’) #3 /home3/coradase/public_html/cora-staging/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(‘’, Array) #4 /home3/coradase/public_html/cora-staging/wp-includes/plugin.php(476): WP_Hook->do_action(Array) #5 /home3/coradase/public_html/cora-staging/wp-admin/admin.php(259): do_action(‘toplevel_page_c…’) #6 {main} thrown in /home3/coradase/public_html/cora-staging/wp-content/plugins/MongoDB/vendor/mongodb/mongodb/src/Client.php on line 124
Client.php (the file referenced in the error code) is a default file that came with the Composer installation. I have not edited the file. The function in Client.php that contains line 124 (referenced in the error) is shown below:
public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
{
$driverOptions += ['typeMap' => self::$defaultTypeMap];
if (! is_array($driverOptions['typeMap'])) {
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
}
if (isset($driverOptions['autoEncryption']['keyVaultClient'])) {
if ($driverOptions['autoEncryption']['keyVaultClient'] instanceof self) {
$driverOptions['autoEncryption']['keyVaultClient'] = $driverOptions['autoEncryption']['keyVaultClient']->manager;
} elseif (! $driverOptions['autoEncryption']['keyVaultClient'] instanceof Manager) {
throw InvalidArgumentException::invalidType('"keyVaultClient" autoEncryption option', $driverOptions['autoEncryption']['keyVaultClient'], [self::class, Manager::class]);
}
}
$driverOptions['driver'] = $this->mergeDriverInfo($driverOptions['driver'] ?? []);
$this->uri = (string) $uri;
$this->typeMap = $driverOptions['typeMap'] ?? null;
unset($driverOptions['typeMap']);
$this->manager = new Manager($uri, $uriOptions, $driverOptions);
$this->readConcern = $this->manager->getReadConcern();
$this->readPreference = $this->manager->getReadPreference();
$this->writeConcern = $this->manager->getWriteConcern();
}
For reference, line 124 is:
$this->manager = new Manager($uri, $uriOptions, $driverOptions);
Again, this code comes directly from the composer installation of mongodb, and has not been edited at all.
I appreciate any insight form the team or anyone who has had this same problem in trying to debug so that the code will properly establish the connection to the database.
Thank you!