Akhil Verma
Akhil Verma

Reputation: 11

Fatal error: Uncaught Error: Class 'MongoDB\Collection' not found in [$path]test.php:10

I have installed the driver of mongo db using pecl and also edit the php.ini file by adding extension="mongodb.so" . When I trying to connect with the database by the following code:

<?php
if($m = new MongoDB\Driver\Manager("mongodb://localhost"))
     echo "Connecting Successfully";
$users = $m->TaskLogger->user->find();
var_dump($users);
?>

If shows the output like that.: Connection is succefull yet not able to connect.

I am using xampp 7.2.5 and php version 7.2.5. In phpinfo page. mongodb extension is added..

Please help me in that issue...Thanks

Upvotes: 1

Views: 396

Answers (1)

After the php module installation you need to use the MongoDB Driver by using composer

Follow this link https://www.php.net/manual/en/mongodb.tutorial.library.php

1.- Install composer 2.- Install the dependency

composer require mongodb/mongodb

3.- And finally add the autoloader in your script, by adding composer autoloader

<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$m = new MongoDB\Driver\Manager("mongodb://localhost")

Upvotes: 1

Related Questions