Mongodb master slave connection

Hi YiiTeam,

How to connect mongodb with master slave config ?

My db will be on different servers.

If master is down then it will be switch between server and i have to select my master db using PHP. Please guide how to do in yii2-mongodb extension ?

Thanks,

Yatin Mistry

For my solution i have set mongodb replica set. It worked

Below is connection string (i have refered here)


// MongoDB

$config["components"]['mongodb'] = [

    'class' => '\yii\mongodb\Connection',

    'dsn' => 'mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/your_database_name?replicaSet=your_replicaset_name&timeoutMS=400000',

];

Hi @yatinmistry5130

I just wanted to check you, if you used read-preferences as well. When I use reapreference as Secondary, I am seeing errors when I read from secondary.