Cannot connect to mongodb on Ubuntu EC2

79 views
Skip to first unread message

Sam Ako

unread,
Apr 7, 2017, 7:00:25 AM4/7/17
to Mongoose Node.JS ODM
I created an ubuntu machine on EC2 a month or so back with the standard free tier image ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170110 (ami-49c9295f) running Ubuntu 14.

Mongodb version is (Mongoose dep in node modules) is 1.4.38
Mongodb version on server gives: MongoDB shell version: 3.0.14

I've tried pretty straight forward connection examples such as is shown in this project: https://github.com/simonholmes/mongoose-default-connection

var dbURI = 'mongodb://localhost/ConnectionTest';
mongoose.connect(dbURI)
mongoose.connection.on('connected', function () {
  console.log('Mongoose default connection open to ' + dbURI);
}

This works locally, but not on my EC2 server. I've tried switching to "mongodb://127.0.0.1/ConnectionTest"
and "mongodb://127.0.0.1:27017/ConnectionTest" but none has worked.

Execution just goes over that line but no connection is established. When i log the connection state, it's always on"connecting".
Also same code worked on a earlier EC2 Ubuntu server I had.

Hope someone here can help :)
Thanks

Gary Rusher

unread,
Jan 16, 2018, 9:27:15 AM1/16/18
to Mongoose Node.JS ODM
I have an ec2 with a working mongo db connection.

mine looks like this.

mongoose.connect(this.database.url(), this.database.options)
     
.then(() => {
        console
.log('Mongoose default connection open');
     
})
     
.catch((err) => {
        console
.log('Mongoose default connection error: ' + err);
     
});


export class Database {
 constructor
(){}
 
//WORKS WITH AUTHENTICATION
 url
() {return 'mongodb://User:passwordUser@localhost:27017/database'; }
 options
() { return {useMongoClient: true }
}



     // mongoose.connection.on('connected', this.onConnected );
     // mongoose.connection.on('error', this.onError)
    /*******************************************************************/
    process.on('SIGINT', this.cleanUp)
  }
Reply all
Reply to author
Forward
0 new messages