title: Deploying to Heroku with node.js & express - how to setup connection to mongoLab?
body: <p>Alright, first time posting here, so I'm hoping I get some feedback.</p>
  
  <ul>
  <li><p>I have two collections that I've successfully uploaded into
  mongoLab/mLab, their names are "allTest" and "myCollection".</p></li>
  <li><p>I want to deploy my site to heroku (which I've successfully done
  already) and be able to pull and display data from mLab.</p></li>
  <li><p>Everything was working great when I was running locally and pulling
  from mongoDB, so I know its because I want to pull from mLab instead of my local instance of mongoDB. However, I'm confused on how to setup the connection to mLab when its deployed on Heroku.</p></li>
  <li><p>I've read some documentation that I should use URI (which I listed below),
  but I'm not sure what else I should change in my code.</p></li>
  </ul>
  
  <p>Here is what I have so far (I edited out my username and password in the URI):</p>
  
  <pre><code>var express = require("express");
  var mongojs = require("mongojs");
  var logger = require("morgan");
  var bodyParser = require('body-parser');
  var app = express();
  
  app.use(bodyParser());
  
  
   var uri = 'mongodb://USERNAME:PASSWORD@ds157702.mlab.com:57702/heroku_r45mjcns';
  
  
  app.use(express.static("public"));
  
  
  var databaseUrl = "mydb";
  var collections = ["myCollection"];
  
  var databaseUrl2 = "testMenu";
  var collections2 = ["allTests"];
  
  
  var db = mongojs(databaseUrl, collections);
  var db2 = mongojs(databaseUrl2, collections2);
  
  
  app.get("/", function(req, res) { 
     res.sendfile('public/home.html');
  });
  
  
  app.get("/find2/:id", function(req, res) {
    var test_id2 = req.param('id');
  
  
  
    db2.allTests.find({"TestName": {$regex:test_id2, $options: 'i'} }, function(error, found) {
      // Log any errors if the server encounters one
      if (error) {
        console.log(error);
      }
      // Otherwise, send the result of this query to the browser
      else {
        res.json(found);
        console.log("From server");
        console.log(found);
  
      }
    });
    });
  
  
  
  
  app.get("/find/:id", function(req, res) {
    var test_id = req.param('id');
  
    db2.allTests.find({"Test": test_id }, function(error, found) {
      // Log any errors if the server encounters one
      if (error) {
        console.log(error);
      }
      // Otherwise, send the result of this query to the browser
      else {
        res.json(found);
        console.log("From server");
        console.log(found);
  
      }
    });
    });
  
  
  
  
  
    app.get("/find/dept/:id", function(req, res) {
    var test_id = req.param('id');
  
    db.myCollection.find({ $or: [ { "WebsiteCategory": test_id }, { "WebsiteCategory2": test_id } ] }, function(error, found) {
      // Log any errors if the server encounters one
      if (error) {
        console.log(error);
      }
      // Otherwise, send the result of this query to the browser
      else {
        res.json(found);
        console.log("From server");
        console.log(found);
  
      }
    });
    });
  
  
  
  
  
  
  
    app.get("/find/dept2/:id", function(req, res) {
    var test_id = req.param('id');
  
    db.myCollection.find({"TestSet": test_id }, function(error, found) {
      // Log any errors if the server encounters one
      if (error) {
        console.log(error);
      }
      // Otherwise, send the result of this query to the browser
      else {
        res.json(found);
        console.log("From server");
        console.log(found);
  
      }
    });
    });
  
  
  
  
  
  
  
  // Set the app to listen on port 3000
  app.listen(process.env.PORT || 3000);
  </code></pre>
  
  <p>`</p>
  
  <p>Specifically, its this piece of code that I was trying out:</p>
  
  <pre><code>     app.get("/find/dept/:id", function(req, res) {
    var test_id = req.param('id');
  
    db.myCollection.find({ $or: [ { "WebsiteCategory": test_id }, { "WebsiteCategory2": test_id } ] }, function(error, found) {
      // Log any errors if the server encounters one
      if (error) {
        console.log(error);
      }
      // Otherwise, send the result of this query to the browser
      else {
        res.json(found);
        console.log("From server");
        console.log(found);
  
      }
    });
    });
  </code></pre>
  
  <p>Any help would be appreciated!!</p>