Justin Sam S Justin Sam S - 2 months ago 15
PHP Question

How could i connect mongodb in laravel 5?

I need to create CRUD Laravel 5 application using MongoDB as a database. I am Asp.net developer new to Laravel but don't know how to use mongoDB with it. Can anyone give me some tutorials or tips that can help me to start?

Also i followed the step which is in following link



If you are on a ubuntu system, then you can follow the below link to install mongo on your system https://gist.github.com/ankur13secret/3878e2cf80ef5ff2bb94 .

Or if you are on any other system, then first download mongo and do the setup.

To start using mongo in laravel, first you have to add mongo driver in your config/database.php file like below

'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => env('DB_HOST', 'localhost'),
            'port'     => env('MONGO_DB_PORT', ''),
            'database' => env('MONGO_DATABASE', ''),

then you need to add these in your .env file like below

MONGO_DATABASE = your_database_name

For using mongo, I am using jenssegers package https://github.com/jenssegers/laravel-mongodb .You need to install it first and you just need to follow few more steps written over there and it will work fine, if everything is good.