title: MongoDB connecting to Node on AWS Mean stack
body: <p>I have been trying for a few days to connect my mongoDB to MEAN stack without success.  Its running on AWS lightsail (Bitnami).  The website itself is running fine, except for any pages that have an ajax/db call, as the database is not connecting/authenticating my connection string.</p>
  
  <p>I am using the mongo,node, express part of the stack, I do not need or know any angular at present. I thought this would be easier than setting up on nodeJS and then adding mongoDB separately (well i did try that first with similar problems), I do intend to learn angualar in future so this is probably better long term.  Server side set up is currently a weakness.</p>
  
  <p>I am using mongoose for the connection.  I can access the database using:
  mongo admin --username root -p password via SSH.</p>
  
  <p>I can also access the db via Rockmongo SSH.  There is currently only one admin user in the database at present i.e. root.</p>
  
  <p>My initial server/startup file is below:</p>
  
  <p>server.js</p>
  
  <pre><code>const app = require('/opt/bitnami/apps/MYAPP/app.js');
  
  require('dotenv').config({ path: 'variables.env' });
  
  const mongoose    = require("mongoose");
  
  mongoose.Promise = global.Promise;  
  
  mongoose.connect(process.env.DATABASE_CONN);
  
  app.listen(3000,function(){
     console.log("Server has started!");
   });
  </code></pre>
  
  <p>variables.env</p>
  
  <pre><code>DATABASE_CONN = mongodb://root:password@127.0.0.1:27017/MYAPPDATABASE
  </code></pre>
  
  <p>I have also tried many other connections strings, exchanging root for bitnami default user, etc.</p>
  
  <p>When I go to my app folder and start the server (npm start or node server.js), the website starts up but with the below mongoDB authentication errors, below is only the first section.</p>
  
  <pre><code>&gt; Server has started!
  Connection error: { MongoError: Authentication failed.
      at /opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/mongodb-core/lib/con
  nection/pool.js:595:61
      at authenticateStragglers (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modu
  les/mongodb-core/lib/connection/pool.js:513:16)
      at Connection.messageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_m
  odules/mongodb-core/lib/connection/pool.js:549:5)
      at emitMessageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
  mongodb-core/lib/connection/connection.js:309:10)
      at Socket.&lt;anonymous&gt; (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
  mongodb-core/lib/connection/connection.js:452:17)
      at emitOne (events.js:116:13)
      at Socket.emit (events.js:211:7)
      at addChunk (_stream_readable.js:263:12)
      at readableAddChunk (_stream_readable.js:250:11)
      at Socket.Readable.push (_stream_readable.js:208:10)
      at TCP.onread (net.js:597:20)
    name: 'MongoError',
    message: 'Authentication failed.',
    ok: 0,
    errmsg: 'Authentication failed.',
    code: 18,
    codeName: 'AuthenticationFailed' }
  </code></pre>
  
  <p>Any help or direction would be much appreciated.  Thank you kindly.</p>
  
  <p>Mos.</p>