I was initially a little unclear about how to connect my Lithium application to my MongoDB replica set while specifying multiple serves, I’ve settled with: Connections::add('default', array( 'type' => 'MongoDb', 'host' => 'localhost:12345,washington.mongo:12345', 'replicaSet' => true, 'database' => 'wiu' ));

I’m listing multiple servers that form my replica set in the host field as a comma separated list. While you technically only need to list one (and the driver should discover the rest), it’s a good idea in case the one you have listed goes down.

Well, secretly, that’s not actually how I’m connecting to MongoDB. I’m also telling Lithium that it should set a read preference of RP_NEAREST. This option isn’t available yet in lithium, but I’ve got an open pull request to fix that. I’m actually connecting to MongoDB like this: Connections::add('default', array( 'type' => 'MongoDb', 'host' => 'localhost:12345,washington.mongo:12345', 'replicaSet' => true, 'database' => 'wiu', 'readPreference' => Mongo::RP_NEAREST ));

Note: Specifying your read preference (and still having everything work) currently requires an un-released version of the MongoDB driver. You either need this fix, so you can build from source. Or presumably the fix will be included in 1.3.0 BETA 3.


Comments »

No Trackbacks
No comments

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
 

Hi, I’m Paul Reinheimer, a developer working on the web.

I wrote a book titled Professional Web APIs with PHP back in 2006, and am currently working in Biomedical Informatics for a major public health company.

I’m working on a project to help developers called WonderProxy which has proxies all over the world. Working on GeoIP development? Now you can finally test properly! We've also released Global Ping Statistics for expected ping times between cities, as well as a Load Testing Tool to measure your site's ability to handle load. Our most recent site checking tool is Where's it Up? which checks your sites availability globally, returning HTTP, DNS, and Traceroute details

My hobbies are cycling, photography, travel, and engaging Allison Moore in intelligent discourse. I frequently write about PHP and other related technologies.

I co-founded:

WonderNetwork Logo

Search