All Projects β†’ leroy-merlin-br β†’ Mongolid Laravel

leroy-merlin-br / Mongolid Laravel

Licence: mit
Easy, powerful and ultrafast MongoDB ODM for Laravel.

Projects that are alternatives of or similar to Mongolid Laravel

Mongo Thingy
πŸƒ The most idiomatic and friendly-yet-powerful way to use MongoDB with Python
Stars: ✭ 49 (-77.93%)
Mutual labels:  odm, mongodb
Laravel Permission Mongodb
Associate users with roles and permissions using Laravel and MongoDB
Stars: ✭ 80 (-63.96%)
Mutual labels:  mongodb, laravel
Laravel Mongodb Passport
A package to get Laravel Passport working with MongoDB
Stars: ✭ 64 (-71.17%)
Mutual labels:  mongodb, laravel
Mongolass
Elegant MongoDB driver for Node.js.
Stars: ✭ 421 (+89.64%)
Mutual labels:  odm, mongodb
Wither
An ODM for MongoDB built on the official MongoDB Rust driver.
Stars: ✭ 174 (-21.62%)
Mutual labels:  odm, mongodb
Laravel Mongodb
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
Stars: ✭ 5,860 (+2539.64%)
Mutual labels:  mongodb, laravel
Laravel Log To Db
Custom Laravel and Lumen 5.6+ Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel/Monolog native logging functionality.
Stars: ✭ 76 (-65.77%)
Mutual labels:  mongodb, laravel
Odmantic
Async ODM (Object Document Mapper) for MongoDB based on python type hints
Stars: ✭ 240 (+8.11%)
Mutual labels:  odm, mongodb
Querybuilderparser
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
Stars: ✭ 126 (-43.24%)
Mutual labels:  mongodb, laravel
Mongorito
🍹 MongoDB ODM for Node.js apps based on Redux
Stars: ✭ 1,409 (+534.68%)
Mutual labels:  odm, mongodb
Mongoengine
MongoEngine is a Python Object-Document Mapper for working with MongoDB. Documentation is available at https://mongoengine-odm.readthedocs.io - there is currently a tutorial, a user guide, and an API reference.
Stars: ✭ 3,632 (+1536.04%)
Mutual labels:  odm, mongodb
Mongodm
A golang object document mapper (ODM) for MongoDB
Stars: ✭ 178 (-19.82%)
Mutual labels:  odm, mongodb
Umongo
sync/async MongoDB ODM, yes.
Stars: ✭ 331 (+49.1%)
Mutual labels:  odm, mongodb
Phalcon Mongodb Odm
MongoDB ODM for Phalcon framework for new mongodb php extension with query builder and rich functionality
Stars: ✭ 42 (-81.08%)
Mutual labels:  odm, mongodb
Mgm
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Stars: ✭ 265 (+19.37%)
Mutual labels:  odm, mongodb
Typegoose
Typegoose - Define Mongoose models using TypeScript classes.
Stars: ✭ 1,189 (+435.59%)
Mutual labels:  odm, mongodb
Php Mongo
MongoDB ODM. Part of @PHPMongoKit
Stars: ✭ 228 (+2.7%)
Mutual labels:  odm, mongodb
Typegoose
Typegoose - Define Mongoose models using TypeScript classes.
Stars: ✭ 1,232 (+454.95%)
Mutual labels:  odm, mongodb
Qxorm
QxOrm library - C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library - Official repository
Stars: ✭ 176 (-20.72%)
Mutual labels:  odm, mongodb
Ts Mongoose
Automatically infer TypeScript interfaces from mongoose schemasπŸ™€
Stars: ✭ 188 (-15.32%)
Mutual labels:  odm, mongodb

Build Status Coverage Status Latest Stable Version Monthly Downloads Latest Unstable Version License

MongoLid

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.

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

Installation

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

composer require leroy-merlin-br/mongolid-laravel

Note: Mongolid Laravel 2.0 only supports Laravel 5.4+. For older versions use the tags:

  • 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).

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

In your config/app.php add 'MongolidLaravel\MongolidServiceProvider' to the end of the $providers array

'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

'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:

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

Notice: It must be outside of connections array.

/*
|--------------------------------------------------------------------------
| 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.

'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.

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'.

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.

'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.

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.

Defining a MongoLid Model

<?php
namespace App;

use MongolidLaravel\MongolidModel;

class User extends MongolidModel
{

}

In a nutshell, that's it!

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

Mongolid Docs

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:

    'providers' => [

        // ...

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

        // ...

    ],

The User model should implement the Authenticatable interface:

<?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.

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:

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

Note: database key is irrelevant.

Troubleshooting

"PHP Fatal error: Class 'MongoDB\Client' not found in ..."

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.

"Class 'MongoDB\Client' not found in ..." in CLI persists even with MongoDB driver installed.

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.

Run php --ini in a terminal to check the .ini that is being used.

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:

$ 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."

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.

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.

Additional information

Mongolid was proudly built by the Leroy Merlin Brazil team. See all the contributors.

Any questions, feel free to contact us.

Any issues, please report here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].