2017 © Pedro Peláez
 

library mongolid-laravel

Easy, powerful and ultrafast MongoDB ODM for Laravel.

image

leroy-merlin-br/mongolid-laravel

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  • Friday, November 17, 2017
  • by gmsantos
  • Repository
  • 30 Watchers
  • 197 Stars
  • 5,268 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 38 Forks
  • 17 Open issues
  • 28 Versions
  • 16 % Grown

The README.md

Build Status Coverage Status Latest Stable Version Monthly Downloads Latest Unstable Version License, (*1)

MongoLid, (*2)

MongoLid (Laravel Package)

Introduction

MongoLid ODM (Object Document Mapper) provides a beautiful, simple implementation for working with MongoDB. Each database collection can have a corresponding "Model" which is used to interact with that collection., (*3)

Note: The ODM implementation is within the (non laravel) mongolid repository., (*4)

Installation

Install with composer require (use one of the above tags if needed)., (*5)

composer require leroy-merlin-br/mongolid-laravel

Note: Mongolid Laravel 2.0 only supports Laravel 5.4+. For older versions use the tags:, (*6)

  • Laravel 4.2 "leroy-merlin-br/mongolid-laravel": "^0.7"
  • Laravel 5.1 "leroy-merlin-br/mongolid-laravel": "2.0.0-beta4"
  • Laravel 5.2 "leroy-merlin-br/mongolid-laravel": "2.0.0-beta6"
  • Laravel 5.3 "leroy-merlin-br/mongolid-laravel": "2.0.0-beta6"

Make sure to set minimum stability to dev when using a beta tag (composer config minimum-stability dev)., (*7)

Note: If you are using Laravel 5.5, the next steps for providers and aliases are unnecessaries. MongoLid supports Laravel new Package Discovery., (*8)

In your config/app.php add 'MongolidLaravel\MongolidServiceProvider' to the end of the $providers array, (*9)

'providers' => [
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    ...
    MongolidLaravel\MongolidServiceProvider::class,
],

(Optional) At the end of config/app.php add 'MongoLid' => 'MongolidLaravel\MongoLidModel' to the $aliases array, (*10)

'aliases' => [
    'App'         => Illuminate\Support\Facades\App::class,
    'Artisan'     => Illuminate\Support\Facades\Artisan::class,
    ...
    'MongoLid'    => MongolidLaravel\MongoLidModel::class,
],

Lastly, be sure to configure a database connection in config/database.php:, (*11)

Paste the settings bellow at the end of your config/database.php, before the last ];:, (*12)

Notice: It must be outside of connections array., (*13)

/*
|--------------------------------------------------------------------------
| MongoDB Databases
|--------------------------------------------------------------------------
|
| MongoDB is a document database with the scalability and flexibility
| that you want with the querying and indexing that you need.
| Mongolid Laravel use this config to starting querying right now.
|
*/

'mongodb' => [
    'default' => [
        'host'     => env('DB_HOST', '127.0.0.1'),
        'port'     => env('DB_PORT_NUMBER', 27017),
        'database' => env('DB_DATABASE', 'my_database'),
        'username' => env('DB_USERNAME', null),
        'password' => env('DB_PASSWORD', null),
    ],
],

For cluster with automatic failover, you need to set cluster key containing all nodes along with replica_set name., (*14)

'mongodb' => [
    'default' => [
        'cluster' => [
            'replica_set' => env('DB_REPLICA_SET', null),
            'nodes' => [
                'primary' => [
                    'host' => env('DB_HOST_A', 'host-a'),
                    'port' => env('DB_PORT_A', 27017),
                ],
                'secondary' => [
                    'host' => env('DB_HOST_B', 'host-b'),
                    'port' => env('DB_PORT_B', 27017),
                ],
            ],
        ],
        'database' => env('DB_DATABASE', 'mongolid'),
        'username' => env('DB_USERNAME', null),
        'password' => env('DB_PASSWORD', null),
    ],
],

You can configure as much nodes as needed, node names (e.g. primary and secondary ) are optional., (*15)

Note: If you don't specify the mongodb key in your config/database.php MongoLid will automatically try to connect to '127.0.0.1:27017' and use a database named 'mongolid'., (*16)

You may optionally provide a connection_string key to set a fully-assembled connection string that will override all other connection options. More info about connection string are found in MongoDB documentation., (*17)

'mongodb' => [
    'default' => [
        'connection_string' => 'mongodb://host-a:27017,host-b:27917/mongolid?replicaSet=rs-ds123',
    ],
],

Also, it is possible to pass options and driver_options to MongoDB Client. Mongolid always overrides typeMap configuration of driver_options to array because it makes easier to use internally with models. Possible options and driver_options are present on MongoDB\Client documentation., (*18)

Basic Usage

To get started, create an MongoLid model. Models typically live in the app/models directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json file., (*19)

Defining a MongoLid Model, (*20)

<?php
namespace App;

use MongolidLaravel\MongolidModel;

class User extends MongolidModel
{

}

In a nutshell, that's it!, (*21)

For further reading about models, CRUD operations, relationships and more, check the Read the Docs: leroy-merlin-br.github.com/mongolid.

Mongolid Docs, (*22)

Authentication

MongoLid Laravel comes with a Laravel auth provider. In order to use it, simply change the 'driver' provider value in your config/auth.php to mongolid and make sure that the class specified in model is a MongoLid model that implements the Authenticatable contract:, (*23)


'providers' => [ // ... 'users' => [ 'driver' => 'mongolid', 'model' => \App\User::class ], // ... ],

The User model should implement the Authenticatable interface:, (*24)

<?php
namespace App;

use Illuminate\Contracts\Auth\Authenticatable;
use MongolidLaravel\MongolidModel;

class User extends MongolidModel implements Authenticatable
{
    /**
     * The database collection used by the model.
     *
     * @var string
     */
    protected $collection = 'users';

    /**
     * Get the name of the unique identifier for the user.
     *
     * @return string
     */
    public function getAuthIdentifierName()
    {
        return '_id';
    }

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->_id;
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
        return $this->remember_token;
    }


    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string  $value
     */
    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        return 'remember_token';
    }
}

Now, to log a user into your application, you may use the auth()->attempt() method. You can use any method regarding authentication., (*25)

Queue Failed Job Provider

Mongolid Laravel replaces Laravel queue failed job provider to use a collection instead of a table. To configure the provider, update failed key on queue.php to include collection name:, (*26)

    'failed' => [
        'database' => 'mongodb',
        'collection' => 'failed_jobs',
    ],

Note: database key is irrelevant., (*27)

Troubleshooting

"PHP Fatal error: Class 'MongoDB\Client' not found in ...", (*28)

The MongoDB\Client class is contained in the MongoDB PHP Library and it requires MongoDB driver for PHP. Here is an installation guide for this driver. The driver is a PHP extension written in C and maintained by MongoDB. MongoLid and most other MongoDB PHP libraries utilize it in order to be fast and reliable., (*29)

"Class 'MongoDB\Client' not found in ..." in CLI persists even with MongoDB driver installed., (*30)

Make sure that the php.ini file used in the CLI environment includes the MongoDB extension. In some systems, the default PHP installation uses different .ini files for the web and CLI environments., (*31)

Run php --ini in a terminal to check the .ini that is being used., (*32)

To check if PHP in the CLI environment is importing the driver properly run php -i | grep mongo in your terminal. You should get output similar to:, (*33)

$ php -i | grep mongo
mongodb
mongodb support => enabled
...

"This package requires php >=7.0 but your PHP version (X.X.X) does not satisfy that requirement.", (*34)

The new (and improved) version 2.0 of Mongolid Laravel requires php7. If you are looking for the old PHP 5.x version, or other Laravel versions, head to the v0.8 branch., (*35)

License

MongoLid & MongoLid Laravel are free software distributed under the terms of the MIT license. Some of the code is based on the work of Taylor Otwell and contributors on laravel/framework, another free software distributed under the terms of the MIT license., (*36)

Additional information

Mongolid was proudly built by the Leroy Merlin Brazil team. See all the contributors., (*37)

Any questions, feel free to contact us., (*38)

Any issues, please report here., (*39)

The Versions

17/11 2017

dev-master

9999999-dev

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

17/11 2017

v2.0.2

2.0.2.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

10/10 2017

v2.0.1

2.0.1.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

06/09 2017

dev-develop

dev-develop

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

06/09 2017

v2.0.0

2.0.0.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

16/08 2017

v2.0.0-beta8

2.0.0.0-beta8

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

09/06 2017

v2.0.0-beta7

2.0.0.0-beta7

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

25/05 2017

v2.0.0-beta6

2.0.0.0-beta6

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

15/05 2017

v2.0.0-beta5

2.0.0.0-beta5

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

15/05 2017

v2.0.0-beta4

2.0.0.0-beta4

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

24/03 2017

v2.0.0-beta10

2.0.0.0-beta10

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

24/03 2017

v2.0.0-beta3

2.0.0.0-beta3

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

11/12 2016

dev-laravel53

dev-laravel53

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

24/08 2016

v2.0.0.x-dev

2.0.0.9999999-dev

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

18/08 2016

dev-serializable-driver-classes

dev-serializable-driver-classes

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

03/08 2016

v2.0.1-beta

2.0.1.0-beta

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

19/07 2016

v2.0.0-beta2

2.0.0.0-beta2

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

19/07 2016

v2.0.0-beta1

2.0.0.0-beta1

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guilherme Guitte

mongodb laravel nosql odm illuminate

15/01 2016

dev-v0.8-dev

dev-v0.8-dev

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

mongodb laravel nosql odm illuminate

15/01 2016

v0.8.0

0.8.0.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

mongodb laravel nosql odm illuminate

15/01 2016

v0.8.x-dev

0.8.9999999.9999999-dev

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

mongodb laravel nosql odm illuminate

27/11 2015

v0.7.3

0.7.3.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate

26/11 2015

v0.7.2

0.7.2.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate

26/11 2015

v0.7.1

0.7.1.0

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate

28/08 2015

v0.7beta

0.7.0.0-beta

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate

18/07 2014

v0.6beta

0.6.0.0-beta

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate

20/02 2014

v0.5beta

0.5.0.0-beta

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate

03/06 2013

v0.1beta

0.1.0.0-beta

Easy, powerful and ultrafast MongoDB ODM for Laravel.

  Sources   Download

MIT

The Requires

 

mongodb laravel nosql odm illuminate