Two Database Connections In Yii Mongodbsuite

How to make two and more database connections in Yii mongodbsuite?

I write 2 DB in main.php

‘components’ => array(

'mongodb' => array(


    'class'             => 'common\extentions\MongoDB',


    'connectionString'  => 'mongodb://localhost:27017/table1',


    'dbName'            => 'table1',


    'fsyncFlag'         => false,


    'persistentConnection' => 'x',


    'replicaSet'        => false,


    'safeFlag'          => true,


    'useCursor'         => false,


),





'mongodb2' => array(


    'class'             => 'common\extentions\MongoDB',


    'connectionString'  => 'mongodb://localhost:27017/table2',


    'dbName'            => 'table2',


    'fsyncFlag'         => false,


    'persistentConnection' => 'x',


    'replicaSet'        => false,


    'safeFlag'          => true,


    'useCursor'         => false,


),

) But how use mongodb2 in query (ex: ->findByAttributes()) i don’t know. Please type some example query to mongodb2.

In my project all models extends \web\extensions\MongoDocument (NOT CActiveRecord). So article Multiple db support in Yii not work for me.

I just add ‘mongodb2’ => array to ‘components’ => array and add to models ( ex: User) who extends EMongoDocument just one method:

public function getMongoDBComponent()

{

return Yii::app()->mongodb2;

}

And it is work!