Reputation: 839
I have a web app which uses a Mongo Database in the backend. Upon starting the Web Server, a connection to the DB is created using MongoClient.connect. From my front-end app I then make numerous axios.post calls to the DB, some of which return a single row, while others return cursors with several rows. Do I need to close some connections to the database at any point in time, either directly on the backend or from the front-end?
Upvotes: 0
Views: 74
Reputation: 23825
You do not need to close your connection anytime when your backend is running. It is good practice to close the connection when your backend process is shutting down though.
process.on('SIGINT', function() {
mongoclient.close()
});
Upvotes: 1