Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
[NO LONGER MAINTANED] MongoDB Package for Laravel 4
PHP
tag: v1.0.0-beta

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/LMongo
tests
.gitignore
.travis.yml
README.md
composer.json
phpunit.xml

README.md

LMongo

LMongo is MongoDB service provider for Laravel 4.

Installation

Add navruzm/lmongo as a requirement to composer.json:

{
    "require": {
        "navruzm/lmongo": "*"
    }
}

And then run composer update

Once Composer has installed or updated your packages you need to register LMongo. Open up app/config/app.php and find the providers key and add:

'LMongo\LMongoServiceProvider'

Then find the aliases key and add following line to the array:

'LMongo'      => 'LMongo\Facades\LMongo',

Finally you need to add the MongoDB database configuration to the config/database.php file:

'mongodb' => array(

        'default' => array(
            'host'     => '127.0.0.1',
            'port'     => 27017,
            'database' => 'laravel',
        )
    ),

Usage

You may get a MongoDB instance by calling the LMongo::connection method:

$LMongo = LMongo::connection();

This will give you an instance of the default MongoDB server. You may pass the server name to the connection method to get a specific server as defined in your mongodb configuration:

$LMongo = LMongo::connection('othermongodbserver');

LMongo uses magic method to pass the collection name to the Database class and return MongoCollection instance. Then you can use any of MongoCollection methods:

$item = $LMongo->collection_name->findOne(array('key', 'value'));

$items = $LMongo->collection_name->find(array('key', 'value'))->limit(5);

$LMongo->collection_name->remove(array('key', 'value'));

Get the MongoDB object:

$mongodb = $LMongo->getMongoDBObject();

$collection_names = $mongodb->getCollectionNames();

Get the MongoClient object:

$mongo = $LMongo->getMongoClientObject();

$databases = $mongo->listDBs();
Something went wrong with that request. Please try again.