gpt4 book ai didi

node.js - 如何使用统一拓扑设置自动重新连接

转载 作者:行者123 更新时间:2023-12-03 12:10:02 24 4
gpt4 key购买 nike

设置后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
}

最佳答案

根据文档,您通常不应该设置 autoReconnect结合 useUnifiedTopology来源:https://mongoosejs.com/docs/connections.html#options

autoReconnect - The underlying MongoDB driver will automatically try to reconnect when it loses connection to MongoDB. Unless you are an extremely advanced user that wants to manage their own connection pool, do not set this option to false.

关于node.js - 如何使用统一拓扑设置自动重新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59465758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com