简体   繁体   中英

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. 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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