title: MongoError: not authorized for query
body: <p>I have a small Node.js/ Express/ Mongoose app which I have running on an AWS - EC2 instance built using Bitnami AMI, whenever I try to run .find on my app MongoDB collection using Chrome Postman I get the following result.</p>
  
  <pre><code>{
      "name": "MongoError"
  }
  
  [MongoError: not authorized for query on projectDB.areas]
  </code></pre>
  
  <p>I tried using the following 3 connection strings but all 3 returned the same result, can someone please help by telling me what I am missing / doing wrong here? Thanks</p>
  
  <pre><code>var connectionString = 'mongodb://localhost:27017/'+dbName;
  var connectionString = 'mongodb://root:bitnami@localhost:27017/'+dbName;
  var connectionString = 'mongodb://root@localhost:27017/'+dbName;
  </code></pre>
  
  <p>My node.js app code:</p>
  
  <p>area.js</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var areaSchema = new Schema({
      name: { type: String, required: true },
  });
  module.exports = mongoose.model('Area', areaSchema);
  </code></pre>
  
  <p>areas.js</p>
  
  <pre><code>var Area = require('../app/models/area');
  var express = require('express');
  var router = express.Router();
  router.route('/').get(function(req, res){
     Area.find(function(err, areas){
          if(err){
              return res.send(err);
          }
          res.json(areas);
          //res.send({sucess:true, areas:areas})
      });
  });
  </code></pre>
  
  <p>app.js</p>
  
  <pre><code>var express = require('express');
  var bodyParser = require('body-parser');
  var mongoose = require('mongoose');
  var areas = require('./routes/areas');
  
  var app = express();
  app.set('port', process.env.PORT || 8080);
  app.use(bodyParser.json({ type: 'application/*+json' }));
  var dbName = 'projectDB';
  var connectionString = 'mongodb://localhost:27017/'+dbName;
  // var connectionString = 'mongodb://root:bitnami@localhost:27017/'+dbName;
  // var connectionString = 'mongodb://root@localhost:27017/'+dbName;
  ////////Tried the above 3 connection strings, none worked...
  mongoose.connect(connectionString, function(err){
    if(err){
      throw err;
    }
  });
  
  var corsOptions = {
    origin: '*',
    allowedHeaders: ['Content-Type'],
    methods: ['POST','GET','PUT','DELETE'],
    credentials: true
  };
  app.use(cors(corsOptions));
  app.use('/api/areas', areas);
  module.exports = app;
  </code></pre>
  
  <p>www.js</p>
  
  <pre><code>var app = require('../app');
  var server = app.listen(app.get('port'), function(){
      console.log('Server running on port: '+ server.address().port);
  });
  </code></pre>