Forked from jatinkshatra/Mongo DB with laravel Integration
Last active
February 26, 2024 08:09
-
-
Save jack2jm/ac3da9a0a0d9914d6057b219d299ca5a to your computer and use it in GitHub Desktop.
This file contains 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 | |
---------- Dump mongodb ------------------ | |
Install this mongodump | |
https://www.mongodb.com/try/download/database-tools | |
Add environment variables | |
C:\Program Files\MongoDB\Tools\100\bin //update your PC path | |
After that run below command | |
mongodump -d scopegenx_test --uri="mongodb+srv://jatin:1245@asd.asdas.mongodb.net" //update your url here | |
Some reference URLS | |
https://stackoverflow.com/questions/63672134/how-to-resolve-mongodump-error-not-recognized | |
https://stackoverflow.com/questions/4880874/how-do-i-create-a-mongodb-dump-of-my-database | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment