Set MongoDB cluster

Igor Khomenko
Added over 4 years ago

I found that to setup MongoDB we should use


so this line points Tigase to the one specific MongoDB server.

Then let imagine a situation with MongoDB cluster with 2 nodes: 1 master and 1 slave.

Above line points Tigase to a master server.

Then, MongoDB master goes down and slave becomes a new master. In this case Tigase won't be able to perform any "WRITE" operations then because its configuration points to the 'dead' master.

How to list all MongoDB nodes in a Tigase configuration?

There is an appropriate method in MongoDB Java driver to set all nodes:

List<ServerAddress> serverAddress = new ArrayList<ServerAddress>();
for(int i=0; i<servers.length; ++i){
   serverAddress.add(new ServerAddress(servers[i],(ports[i]));

mongoClient = new MongoClient(serverAddress);

Replies (1)