-
Notifications
You must be signed in to change notification settings - Fork 142
How to connect to replicaset servers
ichikaway edited this page Aug 24, 2011
·
4 revisions
On replicaset environment, mongo class needs server information and replicaset options.
Here is example database.php for replicaset.
This sample shows connecting blog database of localhost:27021 or localhost:27022 with authentication information(login: loginid, password:passowrd). If set 'replicaset' key, it doesn't use host, port, login, password keys.
// app/config/database.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Mongodb.MongodbSource', //cakephp2.0 style
'host' => '',
'database' => 'blog',
'port' => null,
'prefix' => '',
'persistent' => 'true',
'login' => '',
'password' => '',
'replicaset' => array('host' => 'mongodb://loginid:password@localhost:27021,localhost:27022/blog',
'options' => array('replicaSet' => 'myRepl')),
);
}
This syntax of replicaset host information follows on constructor of MongoClass.