title: Unable to load data from MongoDB Atlas from heroku app after succesful deployment
body: <p>I am a beginner to MERN stack development.I have deployed my nodejs app without any error on heroku.But the app does not load the data from mongodb atlas database.The app connects to database and displays the data without any problem when run locally.Any ideas on how to fix this?</p>
  
  <p>I have already added environment variable on heroku and whitelisted all ip addressed on atlas.But still the app does not load data from the database</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>const express = require('express'); //nodejs framework for creating web apps
  const cors = require('cors');
  const mongoose = require('mongoose');
  const path = require('path');
  
  require('dotenv').config(); //for setting environment variables on server
  
  const app = express(); //creating the app
  
  //Serve static assets if in production
  if(process.env.NODE_ENV ==='production'){
      //Set static folder
      app.use(express.static('client/build'));
  
      app.get('*',(req, res) =&gt; {
          res.sendFile(path.resolve(__dirname,'client','build','index.html'));
      });
  }
  ////////////////////////////////////////
  const port = process.env.PORT || 5000;
  
  app.use(cors()); //for cross origin resource sharing ie.cross domain requests
  app.use(express.json()); //for handling json data
  
  
  const uri = process.env.ATLAS_URI;
  mongoose.connect(uri,{ useNewUrlParser: true, useCreateIndex: true ,useUnifiedTopology: true });
  const connection = mongoose.connection;
  connection.once('open',() =&gt; {
      console.log('Database connection established successfully');
  })
  
  
  const exercisesRouter = require('./routes/exercises');
  const usersRouter = require('./routes/users');
  
  //executes the files in the second argument when user enters the url 'rooturl/firstargument'
  app.use('/exercises',exercisesRouter);
  app.use('/users',usersRouter);
  
  app.listen(port,() =&gt; {
      console.log(`Server is running on port:${port}`);
  });
  </code></pre>
  
  <p><a href="http://justworkout.herokuapp.com/" rel="nofollow noreferrer">http://justworkout.herokuapp.com/</a>
  This is the app url
  The list of exercises should load from the database but nothing is loaded as you can see</p>