matryoshka-model / mongo-wrapper
MongoDB matryoshka wrapper
Installs: 1 045
Dependents: 31
Suggesters: 3
Security: 0
Stars: 0
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/matryoshka-model/mongo-wrapper
Requires
- php: >=5.5.0
- ext-mongo: *
- matryoshka-model/matryoshka: ~0.8.0
- zendframework/zend-paginator: 2.*
- zendframework/zend-servicemanager: 2.*
- zendframework/zend-stdlib: 2.*
Requires (Dev)
- phpunit/phpunit: ~4.3
- satooshi/php-coveralls: dev-master
- zendframework/zend-mvc: 2.*
Suggests
- matryoshka-model/matryoshka: A lightweight framework that provides a standard and easy way to implement a model service layer
- matryoshka-model/mongo-transactional: Perform transactional operations with MongoDB
- matryoshka-model/rest-wrapper: Matryoshka wrapper aimed at creating restful API clients
- matryoshka-model/zf2-matryoshka-module: ZF2 module for matryoshka library
This package is not auto-updated.
Last update: 2025-10-25 21:38:29 UTC
README
Matryoshka wrapper for MongoDB ------------------------------Use MongoDB as data gateway for Matryoshka.
Community
For questions and support please visit the slack channel (get an invite here).
Installation
Install it using composer.
Add the following to your composer.json file:
"require": {
"matryoshka-model/mongo-wrapper": "~0.8.0"
}
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
This wrapper provides extensions and default implementations for using MongoCollection as a datagateway.
Main concepts:
-
Inject a
Matryoshka\Model\Wrapper\Mongo\Criteria\ActiveRecordCriteriainstance into yourMatryoshka\Model\Object\AbstractActiveRecordobjectsThis way the matryoshka Active Record implementation will work with your MongoDB collections
-
Matryoshka\Model\Wrapper\Mongo\PaginatorMongoPaginatorAdapteris a paginator adapter that can be used within paginable criterias -
Matryoshka\Model\Wrapper\Mongo\ResultSetHydratingResultSetmakes the counting functionality working correctly withMongoCursordatasources
NOTES
It's important to always use the HydratingResultSet class included in this package because MongoCursor does not implement the Countable and MongoCursor::count() must be called passing true as parameter.
Components
-
Matryoshka\Model\Wrapper\Mongo\Criteriadirectory contains the aforementionedActiveRecordCriteriamatryoshka criteria. -
Matryoshka\Model\Wrapper\Mongo\Hydratordirectory contains-
ClassMethods, an hydrator that can be used with matryoshka objects when you have MongoDB collections as datagateways -
NamingStrategy\DefaultNamingStrategyandNamingStrategy\UnderscoreNamingStrategy, two strategies that can be overridden to setup the naming rules map of your fields. By default, both convert_idtoid. -
Strategy\*, some common strategies for MongoDB.
-
-
Matryoshka\Model\Wrapper\Mongo\Paginatordirectory contains the aforementionedMongoPaginatorAdapteradapter. -
Matryoshka\Model\Wrapper\Mongo\ResultSetcontains the aforementionedHydratingResultSetwhich extends matryoshka'sHydratingResultSetto make theMongoCursorcounting functionality working properly. -
Matryoshka\Model\Wrapper\Mongo\Servicecontains abstract service factories generally aimed at instantiation of\MongoCollectionand\MongoDbobjects. Usemongocollectionandmongodbconfiguration nodes to respectively setup them (see above).
Continuous integration
CI provided through TravisCI.
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.
