PHPackages                             colinmollenhour/mongodb-php-odm - 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. colinmollenhour/mongodb-php-odm

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

colinmollenhour/mongodb-php-odm
===============================

MongoDb PHP ODM is a simple object wrapper for the Mongo PHP driver classes which makes using Mongo in your PHP application more like an ORM. It is designed for use with Kohana 3 but will integrate equally well with any PHP application.

1.0(12y ago)2106.0k↓16.7%50PHP

Since Aug 7Pushed 8y ago24 watchersCompare

[ Source](https://github.com/colinmollenhour/mongodb-php-odm)[ Packagist](https://packagist.org/packages/colinmollenhour/mongodb-php-odm)[ RSS](/packages/colinmollenhour-mongodb-php-odm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

MongoDb PHP ODM
===============

[](#mongodb-php-odm)

(for lack of a better title)

Overview
--------

[](#overview)

MongoDb PHP ODM is a simple object wrapper for the Mongo PHP driver classes which makes using Mongo in your PHP application more like ORM, but *without* the suck. It is designed for use with [Kohana 3](http://github.com/kohana/core) but will also integrate easily with any PHP application with almost no additional effort.

Design Principles
-----------------

[](#design-principles)

- **Don’t become overly complex.** There are some features that could be implemented, but if they are not it is because they would increase the complexity too much, sacrificing elegance and usability.
- **Keep Mongo schema-less.** I like schema-less. Requiring schema’s in your model definitions is not schema-less. This library let’s you be schema-less.
- **Follow Mongo driver convention.** In many ways, using this library will be pretty similar to using the official driver.
- **Do not add unnecessary overhead.** Sure, it is not as fast as using the driver directly, but I’m quite sure you won’t notice the difference.
- **Don’t Repeat Yourself.** Very little code will be repeated while using this library.
- **Reduce the number of database requests/updates.** Prevent redundant requests and multiple updates to the same document.
- **Choose your favorite design pattern.** This library now supports using Mongo\_Collection directly as a convenience wrapper, or choose between two ActiveRecord like patterns that resemble either the [Table Data Gateway pattern](http://www.martinfowler.com/eaaCatalog/tableDataGateway.html) or the [Row Data Gateway pattern](http://www.martinfowler.com/eaaCatalog/rowDataGateway.html)

Basic Idea
----------

[](#basic-idea)

The basic idea is to boil the usage of the Mongo PHP library down to three classes:

- Mongo\_Database
- Mongo\_Collection
- Mongo\_Document

### Mongo\_Database

[](#mongo_database)

This class encapsulates the functionality of the Mongo connection and the MongoDb class into one since in most cases an application will interface with only one database. Interfacing with more than one database is still possible, but they will not share a single connection. Features afforded by this class:

- Configurations are described with names such as ‘default’. Kohana loads this configuration in the typical Kohana fashion, other frameworks can simply specify it as an argument to `Mongo_Database::instance('default',array(...))` to set the default configuration.
- Database names are never used in your code other than when supplying the configuration the first time. Easily deploy the same application on different database names.
- When used with Kohana, all important database operations can easily have profiling enabled. Profiling output mimics Mongo shell syntax for easy copy/paste debugging in the shell.
- Lazy database connections.

### Mongo\_Collection

[](#mongo_collection)

This class accomplishes the following:

- Allows query results to be accessed as an iterator of models rather than arrays when used in conjunction with Mongo\_Document.
- Combines the functionality of MongoCollection, MongoGridFS and MongoCursor into one base class.
- Allows query building by aggregating query parameters, cursor options, requested fields, etc..
- When used with Kohana, all database requests can easily be profiled.
- Debugging can be made easier by using the `__toString()` method to get a string representing the full query, again mimicking the syntax of the MongoDb shell.

### Mongo\_Document

[](#mongo_document)

This class objectifies a document (or row) in the database. Extend the base class for each of your data models, typically one per collection and enjoy some very simple CRUD operations with niceties like:

- `before_*` and `after_*` methods for you to implement for transparently added functionality such as updating timestamps, validation, etc..
- helpers for all of the Mongo update operations which are aggregated until the next `save()`
- aliased field names so you can use short field names in the database and long names in the code. Take it or leave it.
- auto-loading of referenced documents. E.g. `echo $post->user->email`
- lazy-loading of documents and referenced documents. E.g. the above is two requests, this would only be one: `echo $post->user->id`

See the wiki for more detail.

More Information
----------------

[](#more-information)

@copyright Copyright © 2013 Colin Mollenhour () This project is licensed under the “New BSD” license (see LICENSE.txt). #### Contributors

[](#contributors)

- @panrafal
- @sergeyklay
- @Xobb
- @sebicas
- @kanema
- @semalead
- @bbedwell
- @kohenkatz

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

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

4667d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38738?v=4)[Colin Mollenhour](/maintainers/colinmollenhour)[@colinmollenhour](https://github.com/colinmollenhour)

---

Top Contributors

[![colinmollenhour](https://avatars.githubusercontent.com/u/38738?v=4)](https://github.com/colinmollenhour "colinmollenhour (84 commits)")[![panrafal](https://avatars.githubusercontent.com/u/1268900?v=4)](https://github.com/panrafal "panrafal (26 commits)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (12 commits)")[![paulchubatyy](https://avatars.githubusercontent.com/u/98631?v=4)](https://github.com/paulchubatyy "paulchubatyy (4 commits)")[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (2 commits)")[![sebicas](https://avatars.githubusercontent.com/u/372224?v=4)](https://github.com/sebicas "sebicas (2 commits)")[![kohenkatz](https://avatars.githubusercontent.com/u/88755?v=4)](https://github.com/kohenkatz "kohenkatz (1 commits)")[![kanema](https://avatars.githubusercontent.com/u/212642?v=4)](https://github.com/kanema "kanema (1 commits)")[![bbedwell](https://avatars.githubusercontent.com/u/847756?v=4)](https://github.com/bbedwell "bbedwell (1 commits)")

### Embed Badge

![Health badge](/badges/colinmollenhour-mongodb-php-odm/health.svg)

```
[![Health](https://phpackages.com/badges/colinmollenhour-mongodb-php-odm/health.svg)](https://phpackages.com/packages/colinmollenhour-mongodb-php-odm)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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