在文档MongoClient中,mongo驱动程序选择使用最近的(ping)mongo节点。但写请求只能由主节点处理。能否请您解释一下驱动程序使用节点连接的方式?假设我有一个副本集(从使用驱动程序的机器连接):
rs.status()
set: "mySet", members:[
{name: "mongo1", stateStr: "PRIMARY", pingMs: 900}
{name: "mongo2", stateStr: "SECONDARY", pingMs: 500}
{name: "mongo3", stateStr: "SECONDARY", pingMs: 100}
]
驱动程序设置:
MongoClientOptions options = new MongoClientOptions.Builder()
.readPreference(secondaryPreferred()) //please mention
.build()
List<ServerAddress> nodes = asList(
new ServerAddress("mongo1"),
new ServerAddress("mongo2")
) //no "mongo3"
new MongoClient(options, nodes);
mongo实例会选择什么?写请求将如何路由?