PHPackages                             jenssegers/mongodb-lite - 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. jenssegers/mongodb-lite

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

jenssegers/mongodb-lite
=======================

A lightweight MongoDB database library and model for Laravel 4

v1.1.0(12y ago)121.0k1[1 issues](https://github.com/jenssegers/laravel-mongodb-lite/issues)MITPHPPHP &gt;=5.3.0

Since Dec 13Pushed 10y ago2 watchersCompare

[ Source](https://github.com/jenssegers/laravel-mongodb-lite)[ Packagist](https://packagist.org/packages/jenssegers/mongodb-lite)[ RSS](/packages/jenssegers-mongodb-lite/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Laravel MongoDB Lite
====================

[](#laravel-mongodb-lite)

[![Build Status](https://camo.githubusercontent.com/8886adb7b7e402b732975db76d2b9bd06d643494b03163718192586a859cdcfe/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6a656e737365676572732f6c61726176656c2d6d6f6e676f64622d6c6974652e737667)](https://travis-ci.org/jenssegers/laravel-mongodb-lite) [![Coverage Status](https://camo.githubusercontent.com/f529b21a4c8f56acba5bc295e2c981e4880e11afaacb121d99026e5af7ea79bc/687474703a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a656e737365676572732f6c61726176656c2d6d6f6e676f64622d6c6974652e737667)](https://coveralls.io/r/jenssegers/laravel-mongodb-lite)

The lite version of

The difference between the full version and this lite version is as following:

- Database manager with configurable connections
- Basic model class with accessors and mutators
- Use original MongoCollection operations
- Advanced Eloquent operations like relations
- Query builder support

This lite version returns the native PHP MongoDB collection object instead of hiding them behind the query builder. This can be useful for people who want to do advanced MongoDB stuff using the original methods.

It also ships with a basic Eloquent-like model for extra flexibility. More information about this model can be found below.

Installation
------------

[](#installation)

Install using composer:

```
composer require jenssegers/mongodb-lite

```

Add the service provider in `app/config/app.php`:

```
'Jenssegers\Mongodb\Lite\MongodbServiceProvider',

```

Configuration
-------------

[](#configuration)

Change your default database connection name in `app/config/database.php`:

```
'default' => 'mongodb',

```

And add a new mongodb connection:

```
'mongodb' => array(
    'driver'   => 'mongodb',
    'host'     => 'localhost',
    'port'     => 27017,
    'username' => 'username',
    'password' => 'password',
    'database' => 'database'
),

```

Getting a Collection
--------------------

[](#getting-a-collection)

Once your configuration is in place you can access your collections like this:

```
DB::collection('users');

```

This returns the MongoCollection object associated with the 'mongodb' connection item. If you want to use a different connection use:

```
DB::connection('mongodb2')->collection('users');
// A MongoCollection object

```

Because this returns the native MongoCollection object you can use all of the standard methods:

```
$users = DB::collection('users')->find();
$count = DB::collection('users')->count();
$user = DB::collection('users')->findOne(array('name' => 'John Doe'));

```

Model
-----

[](#model)

A model offers a more flexible way to access a collection.

```
use Jenssegers\MongodbLite\Model as Eloquent;

class User extends Eloquent {

	protected $collection = 'users';

}

```

You can use all standard MongoCollection operations here as well:

```
$users = User::find();

```

### Collections

[](#collections)

All multi-result sets returned by the model return an Laravel Collection object. This object implements the IteratorAggregate PHP interface so it can be iterated over like an array. However, this object also has a variety of other helpful methods for working with result sets. More information about this at

```
$users = User::all();
// Will return a collection of User objects

// Do laravel-collection operations
$user = $users->first();
$count = $users->count();

```

### Accessors &amp; Mutators

[](#accessors--mutators)

Because model objects are returned, you can still define custom methods and use accessors and mutators. More information about this at

```
use Jenssegers\MongodbLite\Model as Eloquent;

class User extends Eloquent {

	protected $collection = 'users';

	// Accessor
	public function getAvatarAttribute()
	{
		$hash = md5($this->attributes['email']);
		return "http://www.gravatar.com/avatar/$hash";
	}

	// Mutator
	public function setPasswordAttribute($value)
	{
		$this->attributes['password'] = crypt($value);
	}
}

```

Which can then be used like this:

```
$user = User::findOne(array('_id' => new MongoId('47cc67093475061e3d9536d2')));
echo $user->avatar;

```

### Insert, Update, Delete

[](#insert-update-delete)

To create a new record in the database from a model, simply create a new model instance and call the save method.

```
$user = new User;
$user->name = 'John Doe';
$user->save();

```

To update a model, you may retrieve it, change an attribute, and use the save method:

```
$user->age = 35;
$user->save();

```

You can create a new model using:

```
$user = User::create(array('name' => 'John'));

```

To delete a model, simply call the delete method on the instance:

```
$user->delete();

```

### Converting To Arrays / JSON

[](#converting-to-arrays--json)

You can convert a model or a collection of models to array or json just like in Eloquent:

```
$user->toArray();
$user->toJson();

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~170 days

Total

2

Last Release

4411d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91980fbd02c3e65e0b2ec1c65e4ca0131f1bbc3929a0a11a7f4f12db5f2036e3?d=identicon)[jenssegers](/maintainers/jenssegers)

---

Top Contributors

[![jenssegers](https://avatars.githubusercontent.com/u/194377?v=4)](https://github.com/jenssegers "jenssegers (26 commits)")

---

Tags

laraveldatabasemodeleloquentmongodbmongo

### Embed Badge

![Health badge](/badges/jenssegers-mongodb-lite/health.svg)

```
[![Health](https://phpackages.com/badges/jenssegers-mongodb-lite/health.svg)](https://phpackages.com/packages/jenssegers-mongodb-lite)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M90](/packages/mongodb-laravel-mongodb)

PHPackages © 2026

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