设置useUnifiedTopology=true
后,“自动重新连接”将停止工作并生成以下错误:
DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology
DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology
DeprecationWarning: The option `autoReconnect` is incompatible with the unified topology
我如何使服务器与该新标志自动重新连接?
我正在使用mongoose.createConnection
连接以下选项:
{
autoReconnect: true,
keepAliveInitialDelay: 300000,
connectTimeoutMS: 300000,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
poolSize: 10,
auth: {
authSource: "admin"
},
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASS
}
答案 0 :(得分:2)
根据文档,通常不应该将autoReconnect
与useUnifiedTopology
结合使用来源:https://mongoosejs.com/docs/connections.html#options
autoReconnect-基础MongoDB驱动程序在失去与MongoDB的连接时将自动尝试重新连接。除非您是要管理自己的连接池的极其高级的用户,否则请勿将此选项设置为false。