How to make two or more database connections in Yii mongodbsuite?
I added 2 DB components in main.php:
'components' => array(
'mongodb' => array(
'class' => 'common\extensions\MongoDB',
'connectionString' => 'mongodb://localhost:27017/table1',
'dbName' => 'table1',
'fsyncFlag' => false,
'persistentConnection' => 'x',
'replicaSet' => false,
'safeFlag' => true,
'useCursor' => false,
),
'mongodb2' => array(
'class' => 'common\extensions\MongoDB',
'connectionString' => 'mongodb://localhost:27017/table2',
'dbName' => 'table2',
'fsyncFlag' => false,
'persistentConnection' => 'x',
'replicaSet' => false,
'safeFlag' => true,
'useCursor' => false,
),
)
But how to use mongodb2 in query (ex: ->findByAttributes()) i don’t know.
Please provide some example queries using the mongodb2 connection above.
I just add ‘mongodb2’ => array to ‘components’ => array and add to models (ex: User) who extends EMongoDocument:
And it is work!