PHPackages                             wcatron/mongo-db-framework - 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. wcatron/mongo-db-framework

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

wcatron/mongo-db-framework
==========================

A MongoDB framework and ODM (assistant) all in one. Extremely flexible for any project.

0.3.4(10y ago)1163[2 issues](https://github.com/wcatron/MongoDB-Framework-PHP/issues)MITPHPPHP &gt;=5.5

Since Feb 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/wcatron/MongoDB-Framework-PHP)[ Packagist](https://packagist.org/packages/wcatron/mongo-db-framework)[ RSS](/packages/wcatron-mongo-db-framework/feed)WikiDiscussions master Synced 2mo ago

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

MongoDB Framework PHP
=====================

[](#mongodb-framework-php)

A MongoDB interface and ODM (assistant) all in one. Extremely flexible for any project.

[![Build Status](https://camo.githubusercontent.com/b776c90683712121c1503f68bd8d9c1bbefb9a0eebdd58f3e9509b7c56354e7d/68747470733a2f2f7472617669732d63692e6f72672f77636174726f6e2f4d6f6e676f44422d4672616d65776f726b2d5048502e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wcatron/MongoDB-Framework-PHP)

Overview
========

[](#overview)

This framework allows you to quickly map objects to documents in a MongoDB collection.

**Setup**

Create models for documents and have them extend *Document*. Implement the `toDocument` and `fromDocument` methods and set the `COLLECTION` constant. Call `MDB::configure()` in your autoload.php file or wherever needed before database calls. You can now perform queries and get php objects back.

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

[](#installation)

Composer
--------

[](#composer)

```
composer require wcatron/mongo-db-framework

```

Models &amp; MDB
================

[](#models--mdb)

### Models

[](#models)

Your classes. Add two functions and a variable and allow any model to create objects.

```
class YourClass extend Document {

	const COLLECTION = 'YourCollection';

	function toDocument() {
		$document = parent::toDocument();
		// Your code setting the documents key/value pairs.
		return $document;
	}

	function fromDocument($document) {
		parent::fromDocument($document);
		// Your code setting the objects properties.
	}
}
```

Saving is extremely simple when you have an object whose class extends document.

`$object->save();`

### MDB

[](#mdb)

Your connection to mongo. To get your documents as objects use this singleton `MDB::getInstance()`

**getObjectByID(Class::class,$id)**

Alternatively you can just call `getByID($id)` on your custom Document object.

This will return your exact object.

**getObjectsFromQuery(Class::class,$query)**

An array of objects based on a custom query. Not all queries need to be written out though.

**getObjectsByKey('ClassName', 'KeyName', $value)**

If you're only searching by one key-value pair. This simple function will work.

Documents &amp; Objects
-----------------------

[](#documents--objects)

By using the toDocument and fromDocument methods classes can customize how their data is stored verses how it is presented to the PHP application. This allows for far greater flexibility than many other ODMs. It does however limit the ability to link object properties directly with document keys. This is the reasoning behind the KeysChanged model. It is understood this may be slower on the application side because of the extra calculations however we believe it is easier to develop if you don't have to worry about how property changes effect the underlying document structure.

Normalizing Arrays and Objects
------------------------------

[](#normalizing-arrays-and-objects)

There are two normalizing methods that can take an object ID or an array of IDs and turn them into the objects they represent only when they are asked for.

Examples:

```
JSON
User Collection
{
	"_id":{"$oid":"1"}
	"username":"JohnDoe2000",
	"friends":["2","3"]
}

```

```
PHP
class User extends Document {
	var $friends; // must match property name for now.
	...

	function User() {
		$this->setArrayForKey('User','friends');
	}
}

$user = User::getByID('1');
$friends = $user->friends->get();

```

IDs as Strings
--------------

[](#ids-as-strings)

All IDs are treated as strings and converted to MongoIDs by the MongoDB class. No converting between MongoIDs and strings. If someone sees a major issue here please speak up.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Recently: every ~17 days

Total

8

Last Release

3664d ago

### Community

Maintainers

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

---

Tags

odmmongodbmongoObject Based

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wcatron-mongo-db-framework/health.svg)

```
[![Health](https://phpackages.com/badges/wcatron-mongo-db-framework/health.svg)](https://phpackages.com/packages/wcatron-mongo-db-framework)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[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)[mmucklo/queue-bundle

Symfony2/3/4/5 Queue Bundle (for background jobs) supporting Mongo (Doctrine ODM), Mysql (and any Doctrine ORM), RabbitMQ, Beanstalkd, Redis, and ... {write your own}

120839.8k](/packages/mmucklo-queue-bundle)[sokil/php-mongo

PHP Object Document Mapper for MongoDB

239161.5k9](/packages/sokil-php-mongo)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11234.3k4](/packages/leroy-merlin-br-mongolid)[moloquent/moloquent

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

120114.6k7](/packages/moloquent-moloquent)

PHPackages © 2026

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