title: NodeJS - MongoDB: use an opening connection
body: <p>It is better to open a new connection or re-use ? when using module, because I'm used to separate my code into several files.</p>
  
  <p>a.js</p>
  
  <pre><code>module.exports = function (req, res) {
  
    new mongodb.... (err, db) { // open a connection
      b(function (err, result) {
        db.close(); // close the connection
        res.send(result);
      });
    });
  
  };
  </code></pre>
  
  <p>b.js</p>
  
  <pre><code>// re-open a connection ? or take the connection of "a.js" ? (passing "db")
  </code></pre>
  
  <blockquote>
    <p>When asynchronous, one must be careful to continue using the same connection (socket). This ensures that the next operation will not begin until after the write completes.</p>
  </blockquote>
  
  <p>Thanks !</p>