Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clusters including master/slave db hosts #12

Closed
agdm opened this issue Jul 31, 2013 · 5 comments
Closed

clusters including master/slave db hosts #12

agdm opened this issue Jul 31, 2013 · 5 comments

Comments

@agdm
Copy link

agdm commented Jul 31, 2013

I'm trying to connect to a cluster of 2 databases.
I'm aware that you build the connection string in the getDsn function.

so I set some extra parameters in the config for mongo like below

'mongodb' => array(

    'cluster'  => 'true',
    'host'     => 'ds031708-a0.mongolab.com',
    'host2'    => 'ds031708-a1.mongolab.com',
    'port'     => port_num,
    'database' => 'db_name',
    'username' => 'user',
    'password' => 'password',
),

and in getDsn I added this block:

    if (isset($config['cluster']) and (isset($config['host2'])) and ($config['cluster'] === 'true')) {
        $dsn .= ',{$host2}:{$port}';
    }

However I continue to get this error:

MongoCursorException
ds031708-a0.mongolab.com:31708: not master and slaveOk=false

Is there something that I'm overlooking?
It seems that the connection string should be built properly if these conditions are met.

@jenssegers
Copy link
Contributor

You can connect to a replica set as described here: #4

'mongodb' => array(
    'host'     => 'db1.example.net:27017,db2.example.net:27017',
    'database' => 'database',
    'options'  => array(
        'replicaSet' => 'myReplSetName'
    )
),

I will try to make this more easier and better documented.

@jenssegers
Copy link
Contributor

I updated the DSN method an readme to allow an easier connection to multiple hosts d8f6b83.

@agdm
Copy link
Author

agdm commented Aug 1, 2013

Looks good to me. Cleaner than what I was trying to implement.
Will test on my end.

@agdm
Copy link
Author

agdm commented Aug 1, 2013

works great.
Thanks

@SundarPPE
Copy link

hi @jenssegers I have followed the same configuration for connecting a cluster of databases.
I'm getting the MongoCursorException not master and slaveOk=false..

'mongodb' => array(
            'driver'   => 'mongodb',
            'host'     => array('db1:27017','db2:27017'),           
            'username' => '',
            'password' => '',
            'database' => 'database',           
            'options'  => array('replicaSet' => 'replicaSetName'),          
        ),

any configuration I have missed here.?

Thanks

alcaeus pushed a commit to alcaeus/laravel-mongodb that referenced this issue Aug 16, 2023
…lications (mongodb#12)

* Add header documentation for classes & traits that can be used in applications
* Precise mixed types when possible
alcaeus pushed a commit that referenced this issue Aug 22, 2023
…lications (#12)

* Add header documentation for classes & traits that can be used in applications
* Precise mixed types when possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants