尝试获取我在admin命令中传递的命令结果, 但这让我退回了MongoError
如何/使用猫鼬lib在哪里设置rs.slaveOk()?
conn = mongoose.createConnection(`mongodb://localhost:port`)
cmd = "someCommand"
conn.db.admin().command(cmd, (err, result)=>{
if(err){
console.error(err)
}
resolve(result)
})
// MongoError: not master and slaveOk=false
答案 0 :(得分:0)
在连接字符串中添加了“读取首选项”和“副本名”
https://mongoosejs.com/docs/connections.html#connection-string-options https://mongoosejs.com/docs/api.html#query_Query-read
var options = {
"db": {
"readPreference": "secondaryPreferred"
},
"replset": {
"rs_name": "replica_name",
}
}
var connection =
mongoose.createConnection(`mongodb://localhost:27030/dbname`, options);