开发者

How to connect to a slave if master goes down -- Replication

I'm playing around with data replication in MongoDb, and I currently have a master and several slave nodes. All of these are running on different ports, but they could just as well be on different machines (I'm testing atm).

My question is, how would I go about connecting to these from my code? Currently, I just have one instance of a db class, which is connected to x port on localhost. Obviously, if this node fails, I want to use the slave at y port on localhost, and if that fails, z po开发者_如何转开发rt on localhost. Shall I use separate db objects for different connections?


Okay, I've looked through the driver source code, and it looks like this is the way to configure clusters:

var db = new mongo.Db('test', new mongo.ServerCluster([new mongo.Server(host, 27018, {}),
                                                    new mongo.Server(host, 27019, {}), 
                                                    new mongo.Server(host, 27017, {})]), {});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜