-2

Currently I am using

public function checkExist($login, $email) 
{
    return $this->where('login', $login)
        ->whereIN('email', $email)
        ->count();
}

Now we want to change our whole db operations with mongoDB. So, how many steps we need to take and how can we write basic ddl and dml operations?

Newton Singh
  • 332
  • 3
  • 9
  • Possible duplicate of [Lumen and MongoDB?](https://stackoverflow.com/questions/31547827/lumen-and-mongodb) – Blackbam Dec 14 '17 at 15:39

1 Answers1

1

You guys are not the first to use Lumen with MongoDB. You even can continue using Eloquent ORM for creating your queries. There are some implementations on Github which are providing a solution to this.

Here is one way to do it (this solution is provided by https://hackernoon.com/how-to-use-mongodb-with-your-lumen-api-e13f36fa0aa6, check the link for more details):

1) Install https://github.com/jenssegers/laravel-mongodb with composer

2) Register the service provider in bootstrap/app.php:

$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
$app->withEloquent();

3) Create config/database.php and add PHP:

return [
    'default' => 'mongodb',
    'connections' => [
        'mongodb' => [ 
            'driver' => ‘mongodb',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', 27017),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'options' => [
                'database' => 'admin' // sets the authentication database required by mongo 3
            ]
        ],
    ],
    ‘migrations’ => ‘migrations’,
];

4) Now you can use MongoDB within your .env file:

DB_CONNECTION=mongodb
DB_HOST=<dbHost>
DB_PORT=27017
DB_DATABASE=<dbName>
DB_USERNAME=<dbUser>
DB_PASSWORD=<dbUserPassword>

An alternative solution probably would be the Moloquent library: https://github.com/moloquent/moloquent

Blackbam
  • 17,496
  • 26
  • 97
  • 150