PHPMongo Yii2 Adapter

0.1.1 2018-01-30 06:46 UTC

This package is auto-updated.

Last update: 2022-07-27 21:09:20 UTC


Yii Adapter for PHPMongo ORM

Build Status Total Downloads Daily Downloads



You can install library through Composer:

composer require phpmongokit/yii2-mongo-odm

Compatibility with PHP 7

PHPMongo currently based on old ext-mongo entension. To use this ODM with PHP 7, you need to add compatibility layer, which implement API of old extension over new ext-mongodb. To start using PHPMongo with PHP7, add requirement alcaeus/mongo-php-adapter to composer. Restrictions for using ODM with compatibility layer you can read in known issues of original adapter.

Add adapter of old ext-mongo API to new ext-mongodb:

composer require alcaeus/mongo-php-adapter

Configuration of Client


return array(
    'components' => array(
        // configure mongo service
        'mongo' => array(
            'class' => 'PHPMongoKit\ODM\Adapter\Yii2\Client',
            'dsn' => 'mongodb://',
            'options' => array(
                'connect' => true,
                'readPreference' => \MongoClient::RP_SECONDARY_PREFERRED,
            'defaultDatabase' => 'database_name',
            'map' => array(
                'database_name' => array(
                    'collectionName1' => '\Collection\Class1',
                    'collectionName2' => '\Collection\Class2',