PHPackages                             julien-c/mongovel - 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. julien-c/mongovel

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

julien-c/mongovel
=================

A Laravel-ish wrapper to the PHP Mongo driver

1.1(11y ago)327.7k5[1 issues](https://github.com/julien-c/mongovel/issues)MITPHPPHP &gt;=5.3.0

Since Apr 30Pushed 11y ago4 watchersCompare

[ Source](https://github.com/julien-c/mongovel)[ Packagist](https://packagist.org/packages/julien-c/mongovel)[ RSS](/packages/julien-c-mongovel/feed)WikiDiscussions master Synced 3w ago

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

Mongovel [![Build Status](https://camo.githubusercontent.com/46a89270f1398c511cc55e6476a4395c5afd803a3b8e2d27a61d6b1f108b7fb8/68747470733a2f2f7472617669732d63692e6f72672f6a756c69656e2d632f6d6f6e676f76656c2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/julien-c/mongovel)
==========================================================================================================================================================================================================================================================================================

[](#mongovel-)

A Laravel-ish wrapper to the PHP Mongo driver
---------------------------------------------

[](#a-laravel-ish-wrapper-to-the-php-mongo-driver)

Most MongoDB packages for Laravel insist on abstracting away the PHP driver and implementing a SQL-like, full-fledged query builder. We think the PHP driver for Mongo is great by itself and Mongo's expressiveness out-of-the-box is actually what makes it awesome.

In that spirit, Mongovel is a **thin wrapper over the PHP driver that makes it more Eloquent-like**:

- you'll be able to **access models like objects**, not arrays
- you'll get query results as **Laravel Collections**
- and some more syntactic sugar, like Facade-inspired **static shortcuts** to make the whole experience more elegant. And remember, you always keep the full power of Mongo methods, as Mongovel always proxies calls to the underlying MongoCollections and MongoCursors. We're sure you'll love it!

### Usage overview

[](#usage-overview)

Enough talking, here's how to use Mongovel:

```
class Book extends MongovelModel
{
}
```

**`GET books/512ce86b98dee4a87a000000`**:

```
public function show($id)
{
	$book = Book::findOne(new MongoId($id));

	// Here, you can access the book's attributes like in Eloquent:
	// $book->title, $book->reviews, etc.
	// $book->id is a string representation of the object's MongoId.

	// Let's say we're an API, so let's just send the object as JSON:

	return $book;
}
```

Mongovel detects that `$id` is a MongoId, and returns an object that will be automatically serialized and sent as JSON by Laravel.

**`POST books`**:

```
public function store()
{
	$book = Input::only('title', 'content');

	Book::insert($book);
}
```

What if we want to update some field on our book? Let's say we're posting a review:

**`POST books/512ce86b98dee4a87a000000/reviews`**:

```
public function reviewStore($id)
{
	$review = Input::all();

	// You can leverage the full power of Mongo query operators:
	Book::update(new MongoId($id),
		array('$push' => array('reviews' => $reviews))
	);

	return Response::json(array('status' => 201), 201);
}
```

Deleting a book is as simple as:

```
public function destroy($id)
{
	Book::remove(new MongoId($id));
}
```

Finally, Mongovel wraps MongoCursor results into Laravel Collections, so you can just do: **`GET books`**:

```
public function index()
{
	$books = Book::find();

	$books->each(function($book) {
		// Do anything you would do on a Laravel Collection
	});

	return $books;
}
```

#### Bulk operations

[](#bulk-operations)

In order to make bulk operations less painful, Mongovel implements the [standard bulk interface](http://docs.mongodb.org/manual/reference/method/js-bulk/):

```
$bulk = Book::initializeOrderedBulk();

$bulk->insert(array('author' => 'Me', 'title' => 'My life'));

$bulk->find(array('author' => 'Me'))
     ->update(array('$push' => array('reviews' => "Awesome!")));

$bulk->find(array('title' => 'My life'))
     ->updateOne(array('$push' => array('reviews' => "Incredible!")));

$bulk->find(array('title' => 'My life, II'))
     ->upsert()
     ->update(array('$push' => array('reviews' => "Can't wait!")));

$bulk->find(array('author' => 'Not me'))
     ->remove();

$bulk->find(array('title' => 'My life, II'))
     ->removeOne();

$bulk->execute();
```

### How to install

[](#how-to-install)

Add `julien-c/mongovel` as a requirement to composer.json, then run `composer update`.

Add Mongovel's service provider to your Laravel application in `app/config/app.php`. In the `providers` array add :

```
'Mongovel\MongovelServiceProvider'
```

Add then alias Mongovel's model class by adding its facade to the `aliases` array in the same file :

```
'MongovelModel' => 'Mongovel\Model'
```

Finally, add a MongoDB hash at the end of your `app/config/database.php` (so, outside of `connections`):

```
'mongodb' => array(
	'default' => array(
		'host'     => 'localhost',
		'port'     => 27017,
		'database' => 'laravel',
	)
)
```

If needed (for MongoHq and the likes), you can specify a `username` and `password` in this array as well.

Any other options will be added as GET parameters to the DSN.

### Authentification

[](#authentification)

To use Mongovel as your Auth provided, you'll simply need to go in the `app/config/auth.php` file and set `mongo` as your driver.

### License

[](#license)

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

### Other MongoDB wrappers in PHP

[](#other-mongodb-wrappers-in-php)

Before writing our own, here are the wrappers we've checked out (and sometimes contributed to):

- [hpaul/mongor](https://github.com/hpaul/mongor)
- [thephpleague/monga](https://github.com/thephpleague/monga)
- [flatline/mongol](https://github.com/xFlatlinex/laravel-mongol)
- [navruzm/lmongo](https://github.com/navruzm/lmongo)

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 64.4% 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 ~83 days

Recently: every ~43 days

Total

8

Last Release

4219d ago

Major Versions

0.6 → 1.02014-12-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/326577?v=4)[Julien Chaumond](/maintainers/julien-c)[@julien-c](https://github.com/julien-c)

---

Top Contributors

[![julien-c](https://avatars.githubusercontent.com/u/326577?v=4)](https://github.com/julien-c "julien-c (112 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (42 commits)")[![arthurdarcet](https://avatars.githubusercontent.com/u/973454?v=4)](https://github.com/arthurdarcet "arthurdarcet (20 commits)")

---

Tags

laravelmongodbLaravel 4mongo

### Embed Badge

![Health badge](/badges/julien-c-mongovel/health.svg)

```
[![Health](https://phpackages.com/badges/julien-c-mongovel/health.svg)](https://phpackages.com/packages/julien-c-mongovel)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M87](/packages/mongodb-laravel-mongodb)[illuminate/database

The Illuminate Database package.

2.8k54.1M11.1k](/packages/illuminate-database)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

9782.1M161](/packages/laravel-ai)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11135.2k6](/packages/leroy-merlin-br-mongolid)

PHPackages © 2026

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