2014-09-29 4 views
7

Java를 사용하여 mongodb 클러스터에 데이터를 삽입하고 있습니다. mongos 인스턴스가 1 개 이상있을 때 백업을 가질 수 있도록 mongos 인스턴스를 두 개 이상 가질 수 있습니까?1 개 이상의 'mongos'인스턴스를 가질 수 있습니까?

다음은 mongos에 연결하는 자바 코드입니다.

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

Java 코드에서 두 번째 몽고 인스턴스를 어떻게 지정합니까? (가능하다면).

미리 감사드립니다.

답변

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

MongoClient docs은 (더미 주소)와 유사하다고 말할 수 있습니다. 서버가 복제 세트 구성원 목록 또는 mongos 서버 목록이 있는지

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 자동으로 감지합니다.

관련 문제