How to close URL connection?

Is it necessary to close the mongoose connection?

  • I've read lots of tutorials but they never seem to call mongoose.connection.close(). When should this be called? Is it not necessary? How often in my application should I be creating a new connection?

  • Answer:

    When you are developing application and making a connection to mongodb database, you use single instance of connection for all database operation in an entire application, so it doesn't matter whether you close a connection or not. But for an instance you are running a test cases for a same application each time you open a new connection and perform a operation for each test cases, in this scenario if you don't close a connection at the end of each test cases, the connections will get piled up and you will run short of memory. So, you decide where it is compulsory to close connection and where not, all based on situation. I hope, I gave satisfactory explanation for your query.

Soni Pandey at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.