title: Server file works fine locally, but once deployed (on Heroku), MongoDB returns "false" instead of JSON
body: <p>When attempting to load JSON data from MongoDb while on the deployed version of the website it returns <code>false</code>. There are no issues when doing it locally. Checking <code>heroku logs</code> in the CLI tells me that in the issues function (located in issues.js), it "can't read property toArray() of undefined".</p>
  
  <p>There are three main files: <strong>server.js</strong></p>
  
  <pre><code>'use strict';
  
  const express = require('express'),
        app = express(),
        issues = require('./routes/issues'),
        users = require('./routes/users'),
        bodyParser = require('body-parser');
  
  
  app.use(bodyParser.json());
  
  // routing for issue management
  app.get('/issues', issues.getAllIssues);
  app.put('/issues/issues.json', issues.putNewIssue);
  app.post('/issues/:issue_id.json', issues.postIssueUpdate);
  app.delete('/issues/:issue_id.json', issues.deleteIssue);
  
  // routing for user management
  app.get('/users', users.getAllUsers);
  app.put('/users/users.json', users.putNewUser);
  
  app.get('/', (req, res) =&gt; {
      res.header('Content-Type', 'text/html');
      res.end('&lt;h1&gt;Issue Manager&lt;/h2&gt;');
  })
  
  let port = process.env.PORT;
  if (port == null || port =='') {
      port = 3000;
  }
  
  app.listen(port);
  </code></pre>
  
  <p>... the function from the <strong>routing.js</strong> that produces the "false" results</p>
  
  <pre><code>const im = require('issue_manager');
  
  exports.getAllIssues = async (req, res) =&gt; {
      let allIssues = await im.issues();
      console.log(allIssues);
      console.log('Operation complete.');
      res.json(allIssues);
  }
  </code></pre>
  
  <p>... the module, <strong>issues.js</strong>, that contains the MongoDb client and processes the request</p>
  
  <pre><code>'use strict';
  
  const MongoClient = require('mongodb').MongoClient;
  
  let db, allIssues; 
  
  (async function() {
      const uri = 'censored';
      const dbName = 'IssueManager';
      let client;
  
      client = MongoClient.connect(uri, 
          { useNewUrlParser: true, 
            useUnifiedTopology: true })
                  .then(data =&gt; {
                      return data;
                  })
                  .catch(err =&gt; {
                      return err;
                  });
  
      try {
          db = (await client).db(dbName);
          allIssues = (await db).collection('Issues').find();
      } catch (e) {
          console.log(e);
      }
  })();
  
  exports.issues = async () =&gt; {
      try {
          return await allIssues
              .toArray()
              .then((data) =&gt; {
                  return data;
              })
              .catch((err) =&gt; {
                  return err;
              });
      } catch (e) {
          console.error(e);
          return false;
      }
  }
  </code></pre>