Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'MongoDB\Driver\Manager' not found

I'm integrating MongoDB with Laravel. I'm following information found in this link jenssegers/laravel-mongodb. I'm successful at integrating MongoDB. But when I run the code it throws this error

FatalErrorException in Client.php line 56: Class 'MongoDB\Driver\Manager' not found

Here is the code

Controller app/Http/Controller/NewController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\User;

class NewController extends Controller
{
    //
    public function index(){
        $var = User::all();
        var_dump($var);
    }
}

And here follows the user.php that is by default provided by Laravel when we create the project

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User  extends Eloquent 
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $collection = 'users_collection';
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

Please tell me why am I getting this error.

Phpinfo --> mongodb section is coming. Here is a screen shot phpinfo

like image 264
garden Avatar asked Mar 10 '16 15:03

garden


People also ask

What is a Mongodb driver?

The official MongoDB Node. js driver allows Node. js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to interact with MongoDB using Promises or via traditional callbacks.


1 Answers

When you are going to connect MongoDB database with any PHP application then you can face this issue if you don't have PHP MongoDB driver.

So first you need to run following command to install Mongodb PHP extension :

sudo apt-get install php-mongodb

Now restart the server :

  sudo service apache2 restart

reference from hdtuto

like image 194
Dev Semicolon Avatar answered Sep 18 '22 16:09

Dev Semicolon