2

I have created a MongoDB instance on an AWS EC2 Ubuntu instance.

MongoDB is running and when I ssh into the machine and run the MongoDB mongod console, I am able to create databases, so I am confident it is running successfully.

However, I am not able to gain access to the database from my local machine in a browser.

I have changed the bindIp in /etc/mongod.conf to 0.0.0.0, and I have opened port 27017 by executing sudo ufw allow 27017 but my browser still times out trying to connect.

When I try to configure the instance using mongod --config /etc/mongod.conf, I get the error:

CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"

This file exists! The relevant portion of the config file looks like this:

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

I have read that you have to enable the REST interface by specifying --rest, but I don't know how to do this since I am starting the database service with the sudo service mongod start command.

My AWS security settings looks like this:

enter image description here

What am I missing?

1 Answer 1

1

You haven't specified which MongoDB version you're using, but since you're showing YAML configuration, I'll assume it's 2.6 or later.

You can enable the REST interface via mongodb.conf with the following (per https://docs.mongodb.com/v3.0/reference/configuration-options/):

net:
   http:
      enabled: true
      RESTInterfaceEnabled: true

According to the MongoDB docs, the REST interface (which is deprecated in 3.2) listens on port 28017 (1000 + the mongod port), so you will have to open the firewall for that port.

Also, I strongly recommend NOT opening up any DB ports to the world (0.0.0.0). Find your laptop's IP (or probably your router's IP as assigned by your ISP) and add that instead.

Your browser likely cannot connect (you didn't specify the exact error) because mongodb doesn't use HTTP or any other browser protocol and your browser doesn't know how to to talk to it. You won't be able to do much with your browser even with the REST interface enabled anyway. Try getting the mongo shell (make sure you get the same version as mongodb on your server) on your laptop and seeing if you can connect to port 27017 with that.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for that, I shall try. It was my understand that it was just the admin console on 28017 that was deprecated, and not the RESTful interface on 27017. Is that a misunderstanding?
Hmm. Now, when trying to look at a database on http//xx.xx.xx.xx:27107/databasename I am getting the message "It looks like you are trying to access MongoDB over HTTP on the native driver port.". Is it no longer possible to query the database over HTTP? I am using the latest version of MongoDB (version 3.2.6 I think).
I don't have an installation over 3.0 to test, but the docs seem to imply they are deprecating http. Does 28017 work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.