I know this might have been asked in a different forms but I’m in a situation where I need to use MongoDB PHP Library with out Composer. The official guide says that it is possible to use it without Composer but provides no example of how to load it into your project; it only mentions the following:
While not recommended, you may also manually install the library using
a source archive attached to the GitHub releases.If you installed the library manually from a source archive, you will
need to manually configure autoloading:
- Map the top-level MongoDB\ namespace to the src/ directory using your preferred autoloader implementation.
- Manually require the src/functions.php file. This is necessary because PHP does not support autoloading for functions.
So, when I use the following example:
require('src/functions.php');
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
I get an error with the following message:
Uncaught Error: Class ‘MongoDB\Client’ not found in xxx
Please note that the driver and the PHP extension is installed and working fine, only that the library isn’t working.
Your help is highly appreciated!