我看的是http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html,当你滚动到"A replicaset connect using no Acknowledge by default and readPreference for secondary"一节时
它向副本集声明了一个连接字符串,如下所示:
MongoClient.connect("mongodb://localhost:30000,localhost:30001/integration_test_?w=0&readPreference=secondary", function(err, db) {
}
我不明白为什么我们需要指定2 hosts
.我认为MongoDB文档已经声明副本集对客户端是透明的.这意味着,客户端只需要连接到主副本集,MongoDB就可以完成这项工作.因此,连接应该只包含一个主机.MongoDB doc声明副本集中必须至少有3 hosts
个,而这个连接字符串只指定了2 hosts
个.
此外,为什么连接字符串没有声明"复制集"?