2017 © Pedro Peláez
 

library mongodb

MongoDb database connection and model

image

hobord/mongodb

MongoDb database connection and model

  • Wednesday, October 5, 2016
  • by hobord
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

laravel-mongodb

And add the service provider in config/app.php:, (*1)

Hobord\MongoDb\MongodbServiceProvider::class,, (*2)

Configuration

And add a new mongodb connection:, (*3)

'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:, (*4)

'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();

The Versions

05/10 2016

dev-master

9999999-dev

MongoDb database connection and model

  Sources   Download

MIT

The Requires

 

The Development Requires

by Balazs Szabo

mongodb database laravel

05/10 2016

dev-develop

dev-develop

MongoDb database connection and model

  Sources   Download

MIT

The Requires

 

The Development Requires

by Balazs Szabo

mongodb database laravel