Forked from jack2jm/Mongo DB with laravel Integration
Created
February 12, 2024 05:50
-
-
Save Bhavya8181/786cc97697ee16d12ea88ebd26cddb78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install mongodb extention - Windows | |
| --- | |
| 1. Download php_mongodb.dll from pecl mongodb php - latest stable dll | |
| 2. Put that DLL to localhost Xampp/php/ext | |
| 3. add line to php.ini - extension=php_mongodb.dll | |
| 4. restart Xampp server. | |
| Download Mongodb Compass for local software to check Data | |
| ------- | |
| Step by step guide - Tutorials | |
| ------- | |
| Server connect - https://adevait.com/laravel/using-laravel-with-mongodb | |
| Crud - https://www.javatpoint.com/mongodb-crud-in-laravel | |
| Basic in local - https://www.geeksforgeeks.org/how-to-install-mongodb-on-laravel-project/ | |
| --- | |
| 1. laravel .nev file setup | |
| ---- | |
| DB_CONNECTION=mongodb | |
| DB_DATABASE_MONGO=scopegenx | |
| DB_DSN="mongodb+srv://<username>:<password>@dbname_url_server_cluster" | |
| ****** mongodb local connection | |
| .env file | |
| ------- | |
| MONGO_DB_HOST=127.0.0.1 | |
| MONGO_DB_PORT=27017 | |
| MONGO_DB_DATABASE=hddatabase | |
| MONGO_DB_USERNAME= | |
| MONGO_DB_PASSWORD= | |
| ---- | |
| database.php config file | |
| -- | |
| 'connections' => [ | |
| ...... | |
| 'mongodb' => [ | |
| 'driver' => 'mongodb', | |
| 'host' => env('MONGO_DB_HOST', 'localhost'), | |
| 'port' => env('MONGO_DB_PORT', 27017), | |
| 'database' => env('MONGO_DB_DATABASE'), | |
| 'username' => env('MONGO_DB_USERNAME'), | |
| 'password' => env('MONGO_DB_PASSWORD'), | |
| 'options' => [] | |
| ], | |
| -------------- | |
| Server side | |
| 'connections' => [ | |
| 'mongodb' => [ | |
| 'driver' => 'mongodb', | |
| 'dsn' => env('DB_URI', 'mongodb+srv://username:password@<atlas-cluster-uri>/myappdb?retryWrites=true&w=majority'), | |
| 'database' => 'myappdb', | |
| ], | |
| ] | |
| 2. Install dependency lib | |
| composer require jenssegers/mongodb | |
| 3. add Service Provider to config/app.php | |
| 'providers' => [ | |
| .... | |
| Jenssegers\Mongodb\MongodbServiceProvider::class, | |
| ] | |
| 4. Model Changes | |
| use Jenssegers\Mongodb\Eloquent\Model as Eloquent; | |
| class Book extends Eloquent | |
| { | |
| protected $connection = 'mongodb'; | |
| protected $collection = 'books'; | |
| ..... | |
| } | |
| ---------------------- | |
| Apache Ubuntu Setup | |
| https://www.fosstechnix.com/how-to-install-mongodb-on-ubuntu-22-04-lts/ | |
| https://stackoverflow.com/questions/38963608/setup-mongodb-extension-for-php7 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment