php access to mongodb master/slave access

Go To


Having a two mongodb servers as master and slave, i wonder what is the best way of using php new mongo(dbaddress) so I can switch between them once one of the servers is down.

I have tested

  new Mongo('', array("replicaSet" => "set"));

where is the master and .11 is the slave. but it didn't work.

I do not want to have two huge block of try and for one server and then repeat the whole thing to catch the connection exception (it really looks stupid).

Can you please help?

2012-04-03 21:39
by Amir


According to the docs, you'd do:

new Mongo('mongodb://,', array("replicaSet" => "set"));
2012-04-03 21:48
by ceejayoz