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.

My answer to "WAMP + Mongo"

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


You need to download the mongo extension .dll file for windows
Here are basic instructions:
http://www.php.net/manual/en/mongo.installation.php#mongo.installation.windows

Another source for these dll files is here
https://github.com/mongodb/mongo-php-driver/downloads

Make sure you download the right version - 32bit or 64bit version depending on your system. If one does not work try another one.

It took me awhile to find the driver that actually worked on my PC and now I don't even remember which one I ended up using. The point is - you may try several different .dll files

Just try one, restart your Apache and launch the file that only has phpinfo(); like it it
Look for the output of that file in browser to see if Mongo section is present. If not then the dll file did not work, try another one, restart Apache and repeat.

Wednesday, November 6, 2013

My answer to "WAMP + Mongo"

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


I have wamp + mongo running on my local PC. That's basically my development environment.
You install them separately.
Download Mongodb for Windows, install it, then start it from command line by just launching the mongod from bin directory from the command prompt. Do not just click on mongod file - you must instead open command prompt, cd into the directory where mongod file is located and start it by just typing mongod
Do not close the prompt - just keep it opened for as long as you want your mongo server to run.

You may need to pre-create the c:/data/db directory on your computer. That's where mongo stores database files by default.

Read instructions just to be sure:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/


Then configure your WAMP server using sample config file in Lampcms distribution. In Lampcms in config/!config.ini edit the 'server' setting in MONGO section, like this:
server = "mongodb://127.0.0.1:27017"

That should work for your local mongodb server.

Tuesday, November 5, 2013

My answer to "Mongo DB question in Config"

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


I will look into that. What I can suggest is to add the 3rd server to your replica set.
From what I understand about mongo replication is that the members of replicate set vote to elect the new primary when old primary goes down.

Read this documentation.

http://docs.mongodb.org/manual/core/replica-set-elections/

From the documentation:

"If you have a three-member replica set, where every member has one vote, the set can elect a primary as long as two members can connect to each other. If two members are unavailable, the remaining member remains a secondary because it cannot connect to a majority of the set's members. If the remaining member is a primary and two members become unavailable, the primary steps down and becomes and secondary."