hobord/mongodb

MongoDb database connection and model
3
Install
composer require hobord/mongodb
PHP:>=5.6.4
License:MIT
Last Updated:Oct 5, 2016
Links: GitHub  ·  Packagist
Maintainer: hobord

laravel-mongodb

And add the service provider in config/app.php:

Hobord\MongoDb\MongodbServiceProvider::class,

##Configuration And add a new mongodb connection:

'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' => [
        'database' => 'admin' // sets the authentication database required by mongo 3
    ]
],

You can connect to multiple servers or replica sets with the following configuration:

'mongodb' => [
    'driver'   => 'mongodb',
    'host'     => ['server1', 'server2'],
    'port'     => env('MONGO_DB_PORT', 27017),
    'database' => env('MONGO_DB_DATABASE'),
    'username' => env('MONGO_DB_USERNAME'),
    'password' => env('MONGO_DB_PASSWORD'),
    'options'  => ['replicaSet' => 'replicaSetName']
],

##Example usage

namespace App;
use Hobord\MongoDb\Model\Model;

class TestModel extends Model
{
    protected $table = "test_collection";

    protected $schema = [
        'pricing' => 'App\PricingField'
    ];
}

#####

namespace App;

use Hobord\MongoDb\Model\Field;

class PricingField extends Field
{

}

#####


TestModel::create([
    'sku'=> '00e8da9c',
    'pricing' => [
        'list' => 500,
        'retail' => 600,
        'action' => 700
    ]
]);

$test = TestModel::where('sku', '00e8da9c')->first();
$test->pricing->retail = 999;
$test->karma = "ok";
$test->save();

$test = TestModel::where('pricing.retail', '>', 600)->skip(1)->take(1)->get();

Related Packages

martinpham/mongodb

Laravel MongoDB with PHP 7's MongoDB driver. Original from jenssegers/mongodb, R...

556 3
jenssegers/mongodb-lite

A lightweight MongoDB database library and model for Laravel 4

1,032 11
chefsplate/laravel-mongodb-queue

Thread-safe MongoDB database queue implementation for Laravel

5,870 9
moloquent/moloquent

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

116,047 120
sirakoff/mongodb

A MongoDB based Eloquent model and Query builder for Laravel 4

12 1