请问node连接可复制集集群后如何得知连接是连到master还是slave?
另外一个问题官方文档让我有些困惑,比如设置集群的readPreference,文档中的
ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST
这个ReadPreference来自哪里?
我的连接方式:
const url = 'mongodb://localhost:4000,localhost:4001/bookstore?replicaSet=myapp';
mongoClient.connect(url,{poolSize:1,},(err,db)=>{
if(err){
return;
}
db.stats((err,status)=>{
console.log(status)
})
console.log('connected to the database');
db.collection('books').find({}).toArray((err,result)=>{
console.log(result)
//db.close()
})
db.collection('books').findOne({price: 20},(err,result)=>{
console.log(result)
})
})