我正在使用nodejs和mongodb开发一个应用,并且尝试使用以下选项连接到mongodb:
let ReadPreference = {
PRIMARY: 'PRIMARY',
PRIMARY_PREFERRED: 'PRIMARY_PREFERRED',
SECONDARY: 'secundary', // in upper or lower case gives the same error
SECONDARY_PREFERRED: 'SECONDARY_PREFERRED',
NEAREST: 'NEAREST'
};
let OPTIONS = {
poolSize: 10,
replicaSet: 'rs0', readPreference
readPreference: ReadPreference.SECONDARY
};
但出现以下错误:
TypeError:无效的读取首选项模式二级。
我不知道他为什么向我扔那个错误,你能帮我解决吗?
代码:
function connection_secondary(){
return new Promise( (resolve,reject)=>{
mongoCliR.connect('mongodb://ANY_IP:27017,ANY_IP:27017', OPTIONS,(err, db)=>{
if(err){
reject(err);
}else{
resolve(db.db('SINCO'));
}
});
})
}