PHPackages                             matryoshka-model/mongo-wrapper - 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. matryoshka-model/mongo-wrapper

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

matryoshka-model/mongo-wrapper
==============================

MongoDB matryoshka wrapper

v0.8.1(10y ago)01.0k11BSD-2-ClausePHPPHP &gt;=5.5.0

Since Sep 11Pushed 9y agoCompare

[ Source](https://github.com/matryoshka-model/mongo-wrapper)[ Packagist](https://packagist.org/packages/matryoshka-model/mongo-wrapper)[ Docs](https://github.com/matryoshka-model/mongo-wrapper)[ RSS](/packages/matryoshka-model-mongo-wrapper/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (7)Versions (10)Used By (1)

[![](https://github.com/matryoshka-model/matryoshka/raw/master/docs/assets/images/matryoshka_logo_hi_res_512.png)](https://github.com/matryoshka-model/matryoshka/blob/master/docs/assets/images/matryoshka_logo_hi_res_512.png)

Matryoshka wrapper for MongoDB ------------------------------ [![Latest Stable Version](https://camo.githubusercontent.com/262bb606bd2f5e938b977f3285289d69852091904b6b45a46c3be3915423bc13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617472796f73686b612d6d6f64656c2f6d6f6e676f2d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/matryoshka-model/mongo-wrapper) [![Build Status](https://camo.githubusercontent.com/746de963bcd23e3ef30e2f732dc434c8b69e60cfdb3c20568b471017527d68f4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d617472796f73686b612d6d6f64656c2f6d6f6e676f2d777261707065722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/matryoshka-model/mongo-wrapper) [![Coveralls branch](https://camo.githubusercontent.com/a1b6ee318dd1adcbc670e4db5f72cdff4636d0384683045d6b4cf463957ae4a6/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6d617472796f73686b612d6d6f64656c2f6d6f6e676f2d777261707065722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/matryoshka-model/mongo-wrapper?branch=master) [![Total Downloads](https://camo.githubusercontent.com/6b3f8bbadfec1ea20bdbf678b3ddc664889e06021ed55053dd9538784de320ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617472796f73686b612d6d6f64656c2f6d6f6e676f2d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/matryoshka-model/mongo-wrapper) [![Matryoshka Model's Slack](https://camo.githubusercontent.com/7b173ae656e6f68002d07e15d05a8323c38983856f38238b76f6baf1821d8b54/687474703a2f2f6d617472796f73686b612d736c61636b696e2e6865726f6b756170702e636f6d2f62616467652e7376673f7374796c653d666c61742d737175617265)](http://matryoshka-slackin.herokuapp.com)

> Use MongoDB as data gateway for [Matryoshka](http://github.com/matryoshka-model/matryoshka).

#### Community

[](#community)

For questions and support please visit the [slack channel](http://matryoshka.slack.com) (get an invite [here](http://matryoshka-slackin.herokuapp.com)).

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

[](#installation)

Install it using [composer](http://getcomposer.org).

Add the following to your `composer.json` file:

```
"require": {
    "matryoshka-model/mongo-wrapper": "~0.8.0"
}

```

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

[](#configuration)

This library provides two abstract factories for `Zend\ServiceManager` to make MongoDb and MongoCollection available as services. In order to use them in a ZF2 application, register the provided factories through the `service_manager` configuration node:

```
'service_manager'    => [
    'abstract_factories' => [
        'Matryoshka\Model\Wrapper\Mongo\Service\MongoDbAbstractServiceFactory',
        'Matryoshka\Model\Wrapper\Mongo\Service\MongoCollectionAbstractServiceFactory',
    ],
],
```

Then in your configuration you can add the `mongodb` and `mongocollection` nodes and configure them as in example:

```
'mongodb' => [
    'Application\MongoDb\YourDatabaseName' => [
        'hosts' => '127.0.0.1:27017',
        'database' => 'yourDatabaseName'
    ],
    ...
],

'mongocollection'    => [
    'Application\DataGateway\YourCollectionName' => [
        'database'   => 'Application\MongoDb\YourDatabaseName',
        'collection' => 'yourCollectionName'
    ],
    ...
],
```

Usage
-----

[](#usage)

This wrapper provides extensions and default implementations for using `MongoCollection` as a datagateway.

Main concepts:

1. Inject a `Matryoshka\Model\Wrapper\Mongo\Criteria\ActiveRecordCriteria` instance into your `Matryoshka\Model\Object\AbstractActiveRecord` objects

    This way the matryoshka [Active Record](http://www.martinfowler.com/eaaCatalog/activeRecord.html) implementation will work with your MongoDB collections
2. `Matryoshka\Model\Wrapper\Mongo\Paginator`

    `MongoPaginatorAdapter` is a paginator adapter that can be used within paginable criterias
3. `Matryoshka\Model\Wrapper\Mongo\ResultSet`

    `HydratingResultSet` makes the counting functionality working correctly with `MongoCursor` datasources

##### NOTES

[](#notes)

It's important to always use the `HydratingResultSet` class included in this package because [`MongoCursor`](http://php.net/manual/en/class.mongocursor.php) does not implement the [`Countable`](http://php.net/manual/en/class.countable.php) and [`MongoCursor::count()`](http://php.net/manual/en/mongocursor.count.php) must be called passing `true` as parameter.

Components
----------

[](#components)

- `Matryoshka\Model\Wrapper\Mongo\Criteria` directory contains the aforementioned `ActiveRecordCriteria` matryoshka criteria.
- `Matryoshka\Model\Wrapper\Mongo\Hydrator` directory contains

    - `ClassMethods`, an hydrator that can be used with matryoshka objects when you have MongoDB collections as datagateways
    - `NamingStrategy\DefaultNamingStrategy` and `NamingStrategy\UnderscoreNamingStrategy`, two strategies that can be overridden to setup the naming rules map of your fields. By default, both convert `_id` to `id`.
    - `Strategy\*`, some common strategies for MongoDB.
- `Matryoshka\Model\Wrapper\Mongo\Paginator` directory contains the aforementioned `MongoPaginatorAdapter` adapter.
- `Matryoshka\Model\Wrapper\Mongo\ResultSet` contains the aforementioned `HydratingResultSet` which extends matryoshka's `HydratingResultSet` to make the `MongoCursor` counting functionality working properly.
- `Matryoshka\Model\Wrapper\Mongo\Service` contains abstract service factories generally aimed at instantiation of `\MongoCollection` and `\MongoDb` objects. Use `mongocollection` and `mongodb` configuration nodes to respectively setup them (see [above](#configuration)).

Continuous integration
----------------------

[](#continuous-integration)

**CI** provided through [TravisCI](http://travis-ci.org/matryoshka-model/mongo-wrapper).

This wrapper is tested against the following MongoDB PHP clients: **1.4.5**, **1.5.0**, **1.5.1**, **1.5.2**, **1.5.3**, **1.5.3**, **1.5.5**, **1.5.6**, **1.5.7**, **1.5.8**, **1.6.0**, **1.6.1**, **1.6.2**, **1.6.3**, **1.6.4**, **1.6.5**, **1.6.6**, **1.6.7**, **1.6.8**, **1.6.9**, **1.6.10**, **1.6.11**, **1.6.12**, **1.6.13**.

---

[![Analytics](https://camo.githubusercontent.com/eaef69514428549a89cc1be9a7f4c882b9694bae86abf4f06b3008d1cb34b484/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d34393635373137362d322f6d6f6e676f2d777261707065723f666c6174)](https://github.com/igrigorik/ga-beacon)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Recently: every ~140 days

Total

7

Last Release

3722d ago

PHP version history (2 changes)v0.3.0PHP &gt;=5.4.0

v0.7.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/504f6b7857bcaa1337d91366a2768d65dcfcdf12ca9281422f7b4d9404aba4ac?d=identicon)[fntlnz](/maintainers/fntlnz)

![](https://avatars.githubusercontent.com/u/120051?v=4)[Leo Di Donato](/maintainers/leodido)[@leodido](https://github.com/leodido)

![](https://avatars.githubusercontent.com/u/3390997?v=4)[Leonardo Grasso](/maintainers/leogr)[@leogr](https://github.com/leogr)

![](https://avatars.githubusercontent.com/u/3627018?v=4)[visa4](/maintainers/visa4)[@visa4](https://github.com/visa4)

---

Top Contributors

[![leodido](https://avatars.githubusercontent.com/u/120051?v=4)](https://github.com/leodido "leodido (86 commits)")[![leogr](https://avatars.githubusercontent.com/u/3390997?v=4)](https://github.com/leogr "leogr (78 commits)")[![fntlnz](https://avatars.githubusercontent.com/u/3083633?v=4)](https://github.com/fntlnz "fntlnz (17 commits)")[![theboolean](https://avatars.githubusercontent.com/u/1123102?v=4)](https://github.com/theboolean "theboolean (1 commits)")[![visa4](https://avatars.githubusercontent.com/u/3627018?v=4)](https://github.com/visa4 "visa4 (1 commits)")

---

Tags

modelwrappernosqldbmvcmongodbmongomatryoshka

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/matryoshka-model-mongo-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/matryoshka-model-mongo-wrapper/health.svg)](https://phpackages.com/packages/matryoshka-model-mongo-wrapper)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M94](/packages/mongodb-laravel-mongodb)[sokil/php-mongo

PHP Object Document Mapper for MongoDB

239167.9k9](/packages/sokil-php-mongo)[moloquent/moloquent

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

120115.7k7](/packages/moloquent-moloquent)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11335.7k7](/packages/leroy-merlin-br-mongolid)

PHPackages © 2026

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