简体   繁体   English

如何在节点js mongo db中设置keepalive(出站连接)

[英]How to set keepalive in node js mongo db(outbound connection)

Please help me out how to implement keepalive in nodejs mongodb.请帮助我如何在nodejs mongodb 中实现keepalive。 As I am using mongo do outbound connections from node js当我使用 mongo 从节点 js 进行出站连接时

How to validate the keepalive is working or not.如何验证keepalive是否有效。

Please help me if you have any idea.如果您有任何想法,请帮助我。

The official documentation given by MongoDB states about different connection operations. MongoDB 给出的官方 文档说明了不同的连接操作。 For implementing a keep alive, you need to use the keepAlive option in the connection URI.要实现保持活动,您需要在连接 URI 中使用keepAlive选项。

// Connection URI
const uri = "mongodb+srv://sample-hostname:27017/?keepAlive=true";

This will enable keepAlive on the TCP socket.这将在 TCP 插槽上启用 keepAlive。

If you want to have a delay before initiating keepAlive on the TCP socket, you can use the keepAliveInitialDelay option in the URI.如果您想在 TCP 套接字上启动 keepAlive 之前有一个延迟,您可以使用 URI 中的keepAliveInitialDelay选项。 The keepAliveInitialDelay should be of an integer type. keepAliveInitialDelay应该是 integer 类型。

// Connection URI
const uri = "mongodb+srv://sample-hostname:27017/?keepAlive=true&keepAliveInitialDelay=30000";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM