Laminas Module which provides Doctrine MongoDB ODM functionality
The DoctrineMongoODMModule integrates Doctrine 2 MongoDB ODM with Laminas quickly and easily. The following features are intended to work out of the box:
- MongoDB support
- Multiple document managers
- Multiple connections
- Support for using existing
- Doctrine CLI support
Laminas MVC Skeleton Application (or compatible architecture)
Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.
composer require doctrine/doctrine-mongo-odm-module
vendor/doctrine/doctrine-mongo-odm-module/config/module.doctrine-mongo-odm.local.php.dist into your application's
config/autoload directory, rename it to
module.doctrine-mongo-odm.local.php, and make the appropriate changes.
With this config file you can configure your mongo connection, add extra annotations to register, add subscribers to
the event manager, add filters to the filter collection, and drivers to the driver chain.
DoctrineMongoODMModule to your
config/application.config.php and create directories
data/DoctrineMongoODMModule/Hydrator and make sure your application has
write access to them.
Installation without composer is not officially supported and requires you to manually install all dependencies
that are listed in
Access the Doctrine command line as following
Access the document manager using this service manager alias:
$objectManager = $serviceManager->get('doctrine.documentmanager.odm_default');
connectionString option has to be set.
|server||'localhost'||IP of mongod instance|
|connectionString||null||If the connection string is specified, it will overwrite other connection options (
|user||null||If set, the client will try to authenticate with given username and password|
|password||null||If set, the client will try to authenticate with given username and password|
|dbname||null||If dbname is not specified, "admin" will be used for authentication. Also, specifiing dbname affecs the defaultDB configuration option, if that's not specified explicitly.|
|options||array()||Array with connection options. More detailed description in http://www.php.net/manual/en/mongoclient.construct.php|
Unit tests rely on a mongo installation so all unit tests are ran through docker. To run all unit tests execute:
docker-compose run --rm php composer test
Running unit tests with code coverage requires you build the docker composer with XDEBUG=1
docker-compose build --build-arg XDEBUG=1
To change docker to a different php version
docker-compose build --build-arg PHP_VERSION=7.3
then run the unit tests as
docker-compose run --rm php composer test-coverage
Run phpcs as
docker-compose run --rm php composer cs-check src test config