PHPackages                             shershams/lmongo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. shershams/lmongo

ActiveLibrary[Database &amp; ORM](/categories/database)

shershams/lmongo
================

LMongo is a MongoDB package for Laravel 4.

v1.0.0-beta(13y ago)019MITPHPPHP &gt;=5.3.0

Since Jan 15Pushed 13y ago1 watchersCompare

[ Source](https://github.com/shershams/lmongo)[ Packagist](https://packagist.org/packages/shershams/lmongo)[ Docs](http://github.com/navruzm/lmongo/)[ RSS](/packages/shershams-lmongo/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

LMongo [![Build Status](https://camo.githubusercontent.com/08121449b1dfcce2c3e56e6beddb1ee409094ad8fc1f6c45d1b88ee261dc175d/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f736865727368616d732f6c6d6f6e676f2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/shershams/lmongo)
====================================================================================================================================================================================================================================================================================================

[](#lmongo-)

LMongo is [MongoDB](http://www.mongodb.org/) package for [Laravel 4](http://laravel.com/). Most part of LMongo is based on [Illuminate/Database](https://github.com/illuminate/database) (Thanks to @taylorotwell)

**Please note that LMongo project is under heavy development, some functionalities are not yet tested. Please report if you find any bug.**

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Query Builder](#query-builder)
    - [Wheres](#wheres)
    - [Advanced Wheres](#advanced-wheres)
    - [Aggregates](#aggregates)
    - [Inserts](#inserts)
    - [Updates](#updates)
    - [Deletes](#deletes)
    - [Pagination](#pagination)
- [Eloquent for MongoDB](#eloquent-for-mongodb)
- [License](#license)

Installation
============

[](#installation)

Add `shershams/lmongo` as a requirement to composer.json:

```
{
    "require": {
        "shershams/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',
'EloquentMongo'   => 'LMongo\Eloquent\Model',
```

Finally you need to publish a configuration file by running the following Artisan command.

```
$ php artisan config:publish shershams/lmongo

```

This will copy the default configuration file to app/config/packages/shershams/lmongo/config.php

Basic Usage
===========

[](#basic-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](http://php.net/manual/en/class.mongocollection.php):

```
$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](http://php.net/manual/en/class.mongodb.php) object:

```
$mongodb = $LMongo->getMongoDB();

$collection_names = $mongodb->getCollectionNames();
```

Get the [MongoClient](http://php.net/manual/en/class.mongoclient.php) object:

```
$mongo = $LMongo->getMongoClient();

$databases = $mongo->listDBs();
```

Select/switch the database:

```
$LMongo->selectDB($dbName);
```

Create the database:

```
$LMongo->createDB($dbName);
```

Query Builder
=============

[](#query-builder)

Wheres
------

[](#wheres)

**Retrieving All Rows From A Collection**

```
$users = LMongo::collection('users')->get();

foreach ($users as $user)
{
    var_dump($user['name']);
}
```

**Retrieving A Single Document From A Collection**

```
$user = LMongo::collection('users')->where('name', 'John')->first();

var_dump($user['name']);
```

**Retrieving A Single Column From A Document**

```
$name = LMongo::collection('users')->where('name', 'John')->pluck('name');
```

**Specifying A Fields**

```
$users = LMongo::collection('users')->get(array('name', 'email'));
```

**Using Where Operators**

```
$users = LMongo::collection('users')->where('votes', 100)->get();
```

**Or Statements**

```
$users = LMongo::collection('users')
                ->where('votes', 100)
                ->orWhere('name', 'John')
                ->get();
```

**Nor Statements**

```
$users = LMongo::collection('users')
                ->where('votes', 100)
                ->norWhere('name', 'John')
                ->get();
```

**Using Where In And Where Not In With An Array**

```
$users = LMongo::collection('users')
                ->whereIn('id', array(1, 2, 3))->get();
```

**Using Where All With An Array**

```
$users = LMongo::collection('users')
                ->whereAll('tags', array('php','mongodb'))->get();

$users = LMongo::collection('users')
                ->whereNin('id', array(1, 2, 3))->get();
```

**Using Where Exists**

```
$users = LMongo::collection('users')
                ->whereExists('updated_at')->get();
```

**Using Where Gt**

```
$users = LMongo::collection('users')
                ->whereGt('votes', 1)->get();
```

**Using Where Gte**

```
$users = LMongo::collection('users')
                ->whereGte('votes', 1)->get();
```

**Using Where Lt**

```
$users = LMongo::collection('users')
                ->whereLt('votes', 1)->get();
```

**Using Where Lte**

```
$users = LMongo::collection('users')
                ->whereLte('votes', 1)->get();
```

**Using Where Between**

```
$users = LMongo::collection('users')
                ->whereBetween('votes', 1, 100)->get();
```

**Using Where Ne**

```
$users = LMongo::collection('users')
                ->whereNe('name', 'John')->get();
```

**Using Where Regex**

```
$users = LMongo::collection('users')
                ->whereRegex('name', '/John/i')->get();
//or
$users = LMongo::collection('users')
                ->whereRegex('name', new MongoRegex('/John/im'))->get();
```

**Using Where Like**

```
$users = LMongo::collection('users')
                ->whereLike('name', 'John','im')->get();
```

There are more where methods in [Query/Builder.php](src/LMongo/Query/Builder.php) file.

**Order By**

```
$users = LMongo::collection('users')
                ->orderBy('name', 'desc')
                ->get();

$users = LMongo::collection('users')
                ->orderBy('name', -1)
                ->get();
```

**Offset &amp; Limit**

```
$users = LMongo::collection('users')->skip(10)->take(5)->get();
```

Advanced Wheres
---------------

[](#advanced-wheres)

**Parameter Grouping**

```
LMongo::collection('users')
            ->where('name', 'John')
            ->orWhere(function($query)
            {
                $query->whereGt('votes', 100)
                      ->whereNe('title', 'Admin');
            })
            ->get();
```

Aggregates
----------

[](#aggregates)

```
$users = LMongo::collection('users')->count();

$price = LMongo::collection('orders')->max('price');

$price = LMongo::collection('orders')->min('price');

$price = LMongo::collection('orders')->avg('price');

$total = LMongo::collection('users')->sum('votes');
```

Distinct
--------

[](#distinct)

```
$emails = LMongo::collection('users')->distinct('email');
```

Inserts
-------

[](#inserts)

**Inserting Document Into A Collection**

```
$id = LMongo::collection('users')->insert(
    array('email' => 'john@example.com', 'votes' => 0),
);
```

**Inserting Multiple Documents Into A Collection**

```
$ids = LMongo::collection('users')->batchInsert(
            array('email' => 'john@example.com', 'votes' => 0),
            array('email' => 'henry@example.com', 'votes' => 0),
        );
```

Updates
-------

[](#updates)

**Updating Documents In A Collection**

```
LMongo::collection('users')
            ->where('id', 1)
            ->update(array('votes' => 1));
```

**Incrementing or decrementing a value of a column**

```
LMongo::collection('users')->increment('votes');

LMongo::collection('users')->decrement('votes');
```

Deletes
-------

[](#deletes)

**Deleting Documents In A Collection**

```
LMongo::collection('users')->where('votes', 100)->delete();
//or
LMongo::collection('users')->where('votes', 100)->remove();
```

**Deleting All Documents From A Collection**

```
LMongo::collection('users')->delete();
//or
LMongo::collection('users')->truncate();
```

Pagination
----------

[](#pagination)

LMongo has pagination support like Laravel's Query Builder.

```
$users = LMongo::collection('users')->orderBy('name')->paginate(10);

foreach ($users as $user)
{
    echo $user['name'];
}

echo $user->links();
```

Eloquent for MongoDB
====================

[](#eloquent-for-mongodb)

It's similar to Eloquent, except few differences:

- It has a `collection` property, not `table`
- Primary key field is `_id`, not `id`
- No Pivot collections for "Many To Many" relationship. So don't use "Many To Many" relationships on a large datasets.

See [Eloquent Docs](http://four.laravel.com/docs/eloquent).

License
=======

[](#license)

Licensed under the [MIT License](http://cheeaun.mit-license.org/).

TODO
====

[](#todo)

- Aggregate/group support
- Indexes
- GridFS

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4914d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/473178?v=4)[Sherzod Kutfiddinov](/maintainers/shershams)[@shershams](https://github.com/shershams)

---

Top Contributors

[![navruzm](https://avatars.githubusercontent.com/u/168341?v=4)](https://github.com/navruzm "navruzm (55 commits)")[![shershams](https://avatars.githubusercontent.com/u/473178?v=4)](https://github.com/shershams "shershams (3 commits)")

---

Tags

laravelmongodbLaravel 4L4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shershams-lmongo/health.svg)

```
[![Health](https://phpackages.com/badges/shershams-lmongo/health.svg)](https://phpackages.com/packages/shershams-lmongo)
```

###  Alternatives

[julien-c/mongovel

A Laravel-ish wrapper to the PHP Mongo driver

327.7k](/packages/julien-c-mongovel)[moharrum/laravel-adminer

Adminer database management tool for your Laravel application.

451.0k](/packages/moharrum-laravel-adminer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
