简体   繁体   English

如何杀死或关闭猫鼬上的特定连接

[英]how to kill or close specific connection on mongoose

I have a two DB server. 我有两个数据库服务器。

-> Primary(27017)

-> Secondary(27022)

Now in my Project, at certain API want to create the request through secondary, After getting the request close the Secondary Connection because it is on demand Request. 现在在我的项目中,某些API希望通过辅助接口创建请求,在获得请求后,关闭辅助连接,因为它是按需请求。 So every time server has to open when demands generate, serve the data and then kill/close that instances. 因此,每次在需求生成时服务器必须打开,服务数据,然后终止/关闭该实例。

By default the command is: 默认情况下,该命令为:

mongoose.connection.close( function () {
    console.log('Secondary Server close Properly');
});

But this will kill the existing Primary Connection as well. 但这也会杀死现有的主连接。 Is there any approach by which I can kill Only Secondary server and primary keep alive 有什么方法可以杀死“仅辅助服务器”和“主服务器保持活动”

You should be using something along the lines of 您应该按照以下方式使用某些东西:

const primary = mongoose.createConnection(...)
const secondary = mongoose.createConnection(...)
// Perform the operations required

// When it comes to closing the connection
secondary.close()

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

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