簡體   English   中英

我可以擁有超過1個'mongos'實例嗎?

[英]Can I have more than 1 'mongos' instance?

我正在使用Java將數據插入到mongodb集群中。 我可以擁有超過1個mongos實例,以便在我的一個mongos關閉時有備份嗎?

這是我連接到mongos的java代碼。

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

如何在Java代碼中指定我的第二個mongos實例? (如果可能的話)。

提前致謝。

MongoClient文檔說你可以,類似於(虛擬地址);

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將自動檢測服務器是否是副本集成員列表或mongos服務器列表。

   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)));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM