title: When to close a MongoDB connection
body: <p>For context, I am writing an ExpressJS app and using the MongoDB node driver, <code>mongodb</code>.</p>
  
  <p>The app will need to talk to the remote DB rapidly at times, depending on how often users are doing things. I understand that the app shouldn't open and close a connection each time it needs data. It should connect once, and there should be an thing named <code>db</code> that you can use for querying, example: <code>db.collection("users").find(...)</code>, and all future DB calls should just use that  <code>db</code> variable.</p>
  
  <p>But if I deploy my app, I am assuming that <code>server.js</code> just executes once at the beginning of the app's life. That would mean that one connection is made once in the entire lifespan of that deployment.</p>
  
  <p>But don't these connections time out? Do I just check that the <code>db</code> var is an open connection, and if not, reconnect before making a call?</p>
  
  <p>Surprisingly, I haven't found many guides, so I don't know the right way, which is why I am asking here. Please let me know if I can ask this question in a better way.</p>