I have a two DB server.
我有一个两个DB服务器。
-> 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. So every time server has to open when demands generate, serve the data and then kill/close that instances.
现在在我的项目中,某些API想要通过辅助创建请求,在获取请求后关闭辅助连接,因为它是按需请求。因此,每次服务器必须在需求生成时打开,提供数据然后终止/关闭这些实例。
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
但这也会杀死现有的主连接。是否有任何方法可以杀死只有辅助服务器和主要保持活着
1 个解决方案
#1
0
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()
#1
0
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()