I am using Java to insert data into mongodb cluster. Can I have more than 1 mongos instance so that I have a backup when 1 of my mongos is down?
我正在使用Java将数据插入到mongodb集群中。我可以拥有超过1个mongos实例,以便在我的一个mongos关闭时有备份吗?
Here is my java code to connect to mongos.
这是我连接到mongos的java代码。
MongoClient mongoClient = new MongoClient("10.4.0.121",6001);
DB db = mongoClient.getDB("qbClientDB");
DBCollection collection = db.getCollection("clientInfo");
How can I specify my second mongos instance in my Java code? (If possible).
如何在我的Java代码中指定我的第二个mongos实例? (如果可能的话)。
Thanks in advance.
提前致谢。
2 个解决方案
#1
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)));
#2
5
The MongoClient docs say that you can, something similar to (the dummy addresses);
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 will auto-detect whether the servers are a list of replica set members or a list of mongos servers.
MongoClient将自动检测服务器是否是副本集成员列表或mongos服务器列表。
#1
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)));
#2
5
The MongoClient docs say that you can, something similar to (the dummy addresses);
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 will auto-detect whether the servers are a list of replica set members or a list of mongos servers.
MongoClient将自动检测服务器是否是副本集成员列表或mongos服务器列表。