PHPackages                             php-loep/monga - 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. php-loep/monga

Abandoned → [league/monga](/?search=league%2Fmonga)Library[Database &amp; ORM](/categories/database)

php-loep/monga
==============

MongoDB Abstraction Layer

1.2.4(10y ago)32919531[3 issues](https://github.com/php-loep/monga/issues)[1 PRs](https://github.com/php-loep/monga/pulls)MITPHPPHP &gt;=5.4.0

Since Nov 15Pushed 8y ago22 watchersCompare

[ Source](https://github.com/php-loep/monga)[ Packagist](https://packagist.org/packages/php-loep/monga)[ Docs](https://github.com/thephpleague/monga)[ RSS](/packages/php-loep-monga/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (9)Dependencies (3)Versions (21)Used By (0)

Monga
=====

[](#monga)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b2490d10b354472ba0baa7cdff0823f261f4a1f0ae0ad78943cbe06ac1aeabf2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65616775652f6d6f6e67612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/monga)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/9d8cb5b1dae23b2c4195a7d4dab0cb1a5102f88240abfa9905dbf50cfec3ea4c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468657068706c65616775652f6d6f6e67612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thephpleague/monga)[![Total Downloads](https://camo.githubusercontent.com/c1c3862fcc559e5be1edeaa96f8a703704c01c72eaff729bba91ac9332bc298d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f6d6f6e67612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/monga)

A simple and swift MongoDB abstraction layer for PHP 5.4+

What's this all about?
----------------------

[](#whats-this-all-about)

- An easy API to get connections, databases and collections.
- A filter builder that doesn't make your mind go nuts.
- All sorts of handy update functions.
- An abstraction for sorting single results.
- GridFS support for a Mongo filesystem.
- Easy aggregation and distinct values.

Vision
------

[](#vision)

Monga was created with the acknowledgment of the MongoDB PHP package already being pretty awesome. That's why in a lot of cases Monga is just a simple wrapper around the MongoDB classes. It provides some helpers and helps you set up queries using a query builder. Which you can also choose not to use! Everything will still work accordingly. During the development, a lot of planning has gone into creating a nice streamlined API that closely follows the MongoDB base classes, while complementing existing query builders for SQL-like databases.

Install
-------

[](#install)

Via Composer

```
$ composer require league/monga
```

Usage
-----

[](#usage)

```
use League\Monga;

// Get a connection
$connection = Monga::connection($dns, $connectionOptions);

// Get the database
$database = $connection->database('db_name');

// Drop the database
$database->drop();

// Get a collection
$collection = $database->collection('collection_name');

// Drop the collection
$collection->drop();

// Truncate the collection
$collection->truncate();

// Insert some values into the collection
$insertIds = $collection->insert([
	[
		'name' => 'John',
		'surname' => 'Doe',
		'nick' => 'The Unknown Man',
		'age' => 20,
	],
	[
		'name' => 'Frank',
		'surname' => 'de Jonge',
		'nick' => 'Unknown',
		'nik' => 'No Man',
		'age' => 23,
	],
]);

// Update a collection
$collection->update(function ($query) {
	$query->increment('age')
		->remove('nik')
		->set('nick', 'FrenkyNet');
});

// Find Frank
$frank = $collection->findOne(function ($query) {
	$query->where('name', 'Frank')
		->whereLike('surname', '%e Jo%');
});

// Or find him using normal array syntax
$frank = $collection->find([
	'name' => 'Frank',
	'surname' => new MongoRegex('/e Jo/imxsu')
]);

$frank['age']++;

$collection->save($frank);

// Also supports nested queries
$users = $collection->find(function ($query) {
	$query->where(function ($query) {
		$query->where('name', 'Josh')
			->orWhere('surname', 'Doe');
	})->orWhere(function ($query) {
		$query->where('name', 'Frank')
			->where('surname', 'de Jonge');
	});
});

// get the users as an array
$arr = $users->toArray();
```

Aggregation
-----------

[](#aggregation)

A big part of the newly released MongoDB pecl package is aggregation support. Which is super easy to do with Monga:

```
$collection->aggregate(function ($a) {
	$a->project([
		'name' => 1,
		'surname' => -1,
		'tags' => 1,
	])->unwind('tags');

	// But also more advanced groups/projections
	$a->project(function ($p) {
		$p->select('field')
			->select('scores')
			->exclude('other_field');
	})->group(function ($g) {
		$g->by(['$name', '$surname'])
			->sum('scores');
	});
});
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Frank de Jonge](https://github.com/frankdejonge)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~63 days

Recently: every ~39 days

Total

20

Last Release

3728d ago

Major Versions

0.2.3 → 1.0.02013-04-11

PHP version history (2 changes)0.1.0PHP &gt;=5.3.3

1.1.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b79ef64367fa25261d8353dbd941670f2b5f2617de247e4b98c089a025ca543a?d=identicon)[philsturgeon](/maintainers/philsturgeon)

![](https://www.gravatar.com/avatar/3a5327d87a2a2d37a9412d5706442399763d86cb773f81adbe58c8d749393e2d?d=identicon)[alexbilbie](/maintainers/alexbilbie)

![](https://www.gravatar.com/avatar/19e009a3db20614ee9d5fa2aa54bec3b7a7bc468e6e567afca15d62ef8fda4b8?d=identicon)[bcrowe](/maintainers/bcrowe)

---

Top Contributors

[![bcrowe](https://avatars.githubusercontent.com/u/752603?v=4)](https://github.com/bcrowe "bcrowe (90 commits)")[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (89 commits)")[![philsturgeon](https://avatars.githubusercontent.com/u/67381?v=4)](https://github.com/philsturgeon "philsturgeon (2 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (2 commits)")[![acim](https://avatars.githubusercontent.com/u/2791202?v=4)](https://github.com/acim "acim (1 commits)")[![Madthumb](https://avatars.githubusercontent.com/u/13104722?v=4)](https://github.com/Madthumb "Madthumb (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![georgeholt](https://avatars.githubusercontent.com/u/2599611?v=4)](https://github.com/georgeholt "georgeholt (1 commits)")

---

Tags

mongodb

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/php-loep-monga/health.svg)

```
[![Health](https://phpackages.com/badges/php-loep-monga/health.svg)](https://phpackages.com/packages/php-loep-monga)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[doctrine/mongodb-odm

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k23.3M302](/packages/doctrine-mongodb-odm)[friendsofsymfony/elastica-bundle

Elasticsearch PHP integration for your Symfony project using Elastica

1.3k17.2M47](/packages/friendsofsymfony-elastica-bundle)[doctrine/mongodb-odm-bundle

Symfony Doctrine MongoDB Bundle

38418.7M195](/packages/doctrine-mongodb-odm-bundle)

PHPackages © 2026

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