Saturday, November 9, 2013

My answer to "Mongo DB question in Config"

This is my answer to a Question on Support site for LampCMS project


OK, the replica set is a bit tricky, but not all that difficult.
First rule to remember - do not point to server by IP address - always use the domain name of member of replica set. If you don't have your own DNS server then just add the name to ip mappings to your hosts file

Then use this type of mongo connection string in your !config.ini

mongodb://rs1.example.com:27017,rs2.example.com:27017/?replicaSet=myReplSetName

I took this example from php.net documentation here:
http://php.net/manual/en/mongo.connecting.rs.php

There are other ways to connect to replica set but for Lampcms the easiest way it to just have this connection string in !config.ini in MONGO section as value of 'server'

Again - its very important to use domain names and not ip addresses. We learned this the hard way when we first started using mongo replica set at our project at my job. Yes, I work with mongo replicate set from php and node.js every day. I am not a server admin or DBA so I don't really touch the servers. I am a developer and write programs that use MongoDB in production at a pretty large scale. We use sharding and replica sets.

No comments:

Post a Comment