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

Node.js 如何使用统一拓扑设置自动重新连接,node.js,mongoose,node-mongodb-native,Node.js,Mongoose,Node Mongodb Native,设置useUnifiedTopology=true后,自动重新连接停止工作并产生以下错误: DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology DeprecationWarning: T

设置
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
useinfiedtopology
结合使用

autoReconnect-底层MongoDB驱动程序在与MongoDB失去连接时将自动尝试重新连接。除非您是希望管理自己的连接池的高级用户,否则不要将此选项设置为false


我没有使用mongoose,但是原始mongodb模块有问题,它不允许我使用autoReconnect=true:(节点:4642)弃用警告:选项
autoReconnect
与统一拓扑不兼容,请访问http://... (节点:4642)弃用警告:选项
重新连接
与统一拓扑不兼容,请访问了解更多信息http://...Mongoose 在下面使用mongodb nodejs驱动程序。所以同样的原则也适用:)是的,但是新的统一拓扑不允许旧的选项“自动重新连接”和“重新连接”。这正是我的观点:)你不应该根据文档设置这些属性。您应该实现自己的重新连接尝试。查看此库以获取示例:这是braindead。所以现在成千上万的人将重新实现自己的重新连接逻辑,并创建许多定制的buggy重新连接逻辑。。。