2014-09-29 16 views
7

Sto usando Java per inserire dati nel cluster mongodb. Posso avere più di 1 istanza di mongos in modo da avere un backup quando 1 dei miei mongos è inattivo?Posso avere più di 1 istanza 'monghi'?

Ecco il mio codice Java per connettersi a mongos.

MongoClient mongoClient = new MongoClient("10.4.0.121",6001); 
DB db = mongoClient.getDB("qbClientDB"); 
DBCollection collection = db.getCollection("clientInfo"); 

Come specificare la mia seconda istanza di mongos nel mio codice Java? (Se possibile).

Grazie in anticipo.

risposta

4
public MongoClient(List<ServerAddress> seeds, 
       MongoClientOptions options) 


//Creates a Mongo based on a list of replica set members or a list of mongos. It will find all members (the master will be used by default). If you pass in a single server in the list, the driver will still function as if it is a replica set. If you have a standalone server, use the Mongo(ServerAddress) constructor. 

//If this is a list of mongos servers, it will pick the closest (lowest ping time) one to send all requests to, and automatically fail over to the next server if the closest is down. 

    MongoClient mongoClient = new MongoClient(Arrays.asList(
    new ServerAddress("10.4.0.121",6001), 
    new ServerAddress("10.4.0.122",6001), 
    new ServerAddress("10.4.0.123",6001))); 
5

Il MongoClient docs dice che è possibile, qualcosa di simile a (gli indirizzi fittizi);

MongoClient mongoClient = new MongoClient(Arrays.asList(
    new ServerAddress("10.4.0.121",6001), 
    new ServerAddress("10.4.0.122",6001), 
    new ServerAddress("10.4.0.123",6001))); 

MongoClient rileva automaticamente se i server sono un elenco di membri del set di replica o di un elenco di server Mongos.

Problemi correlati