Last active
July 14, 2023 10:41
-
-
Save jatinkshatra/b99643202df31310617052865238ca59 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' => [] | |
], | |
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'; | |
..... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment