0

I have an EC2 instance running on elastic beanstalk host our website. Our website is a node app that connects to our replicaset and then makes a query, but that query just disappears into oblivion. Here is the code that runs when the server starts:

(function() {
    logger.log('info', 'called');
    const MongoClient = require('mongodb').MongoClient;
    var client = new MongoClient();
    client.connect(process.env.MONGO_CONNECTION_STRING, mongoClientOptions, function(err, db) {
        if(err) return logger.log('error', err.message);

        logger.log('info', 'Connected to mongodb replset.');

        var collection = db.collection(SESSION_COLLECTION_NAME);
        collection.findOne({}, function(err, doc) {
            if(err) return logger.log('error', err.message);
            logger.log('info', doc);
        });
    });
})();

This code works fine locally. But on the server, all I ever see is Connected to mongodb replset. and then nothing else. No error log or info log.

One thing to note is that the mongodb database exists in the same AWS region as our EC2 instance, but it's hosted by a third party called Compose.

So what could be going on here? I can't figure out how to debug this further.

Ben Zuill-Smith
  • 3,504
  • 3
  • 25
  • 44
  • Is MongoDB running inside of EC2 instance or MongoDB is trying to access EC2 instance? – Kumaresh Babu N S Jan 16 '17 at 15:50
  • My web server is in an EC2 instance. I do not know what mongodb is running on. All I am given is the URL for my Replica Set. But I know that under the hood, my mongodb database is run on AWS in the same region. – Ben Zuill-Smith Jan 16 '17 at 16:07
  • Have you opened Mongo DB port (27017) in Web server EC2 instance's Security group? – Kumaresh Babu N S Jan 16 '17 at 16:58
  • Yes. My outbound rule is ```All traffic All All 0.0.0.0/0``` which are Type, Protocol, Port range, and Source respectively. We can access a third party API just fine, so we know this rule is working. And AWS connections like this should be stateful, so inbound rules shouldn't affect the mongodb connection... – Ben Zuill-Smith Jan 16 '17 at 17:11
  • Web Server Instance need to access Mongo DB instance. Make sure in Mongo DB Instance security group, you should open MongoDB port for your web server instance's ip. Both instances are running in same vpc you use private ip of web server. – Kumaresh Babu N S Jan 16 '17 at 17:16
  • They aren't in the same VPC though. I have no control over the mongodb instance. It is hosted by compose.com. They only give me a replset URL to connect to. – Ben Zuill-Smith Jan 16 '17 at 17:49
  • Yeah I got it. Have you opened Mongo DB port for Web server EC2 instance's security group? – Kumaresh Babu N S Jan 17 '17 at 03:50

0 Answers0