lundi 18 avril 2016

how to make read from slave and write at master in mongodb with replicaset using laravel

I am working with laravel 5.1 with mongodb. For mongodb i am using jenssegers mongo configuration..

Now i have to make mongodb replica set and i want to make read operation only from slave & write operation at master..

In laravel's documentation i read that we can make separation in read & write like below:

'mysql' => [
    'read' => [
        'host' => '192.168.1.1',
    ],
    'write' => [
        'host' => '196.168.1.2'
    ],
    'driver'    => 'mysql',
    'database'  => 'database',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
],

Here is link for how to set configuration in laravel..

In jenssegers documentation here is configuration for replication.

'mongodb' => [
    'driver'   => 'mongodb',
    'host'     => ['server1', 'server2'],
    'port'     => env('DB_PORT', 27017),
    'database' => env('DB_DATABASE'),
    'username' => env('DB_USERNAME'),
    'password' => env('DB_PASSWORD'),
    'options'  => ['replicaSet' => 'replicaSetName']
],

So if i change this to:

'mongodb' => [
        'driver'   => 'mongodb',
        'read'     => ['host' => '192.168.1.1'],
        'write'    => ['host' => '192.168.1.2'],
        'port'     => env('DB_PORT', 27017),
        'database' => env('DB_DATABASE'),
        'username' => env('DB_USERNAME'),
        'password' => env('DB_PASSWORD'),
        'options'  => ['replicaSet' => 'replicaSetName']
    ],

So can i use the above configuration in jenssegers mongo db configuration??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire