title: Best way to connect to MongoDB using Node.js
body: <p>I've read a few guides on how to use Mongo with Node, and they all seem to connect to databases differently. One particular way that worked well for me was:</p>
  
  <pre><code>MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
    if(err) { return console.dir(err); }
  
    db.createCollection('users', function(err, collection) {});
  
    //Do all server/database operations in here
  
  });
  </code></pre>
  
  <p>However, this seems inefficient/odd to me, I would have to reconnect to the database every time there is an <code>app.get()</code>, like for making a new user or retrieving information. </p>
  
  <p>Another way that seems better suited to me is</p>
  
  <pre><code>var mongoose = require("mongoose")
  var db = mongoose.connect("localhost:27107/users");
  
  db.createCollection('users', function(err, collection) {});
  </code></pre>
  
  <p>I've seen several sites do something along these lines, but I personally can't get the above to work. I keep getting the error <code>TypeError: db.createCollection is not a function</code> server-side. So, my question is why the above code doesn't work, if the first code is a good alternative, and if there are any other ways to do this.</p>