0

In order to use MongoDB on my node.js AWS EC2 instance do I simply install MongoDB and create a database within the instance via the command line after logging in via SSH?

In other words do I simply create a DB in the EC2 instance for my web app just as I would locally on my machine?

3 Answers3

2

just from long (and at the beginning painful) experience with EC2 & MongoDB..here are some gotcha's. I am assuming you are just starting off from your question - so I am going to assume a minimal setup:

  1. If you install MongoDB on a server with access to the Internet, then make sure you also apply MongoDB roles to your DB. Do not, I repeat, do not leave it open to the world. Admin and read/write roles are critical here, and MongoDB docs will help you. BTW, even if it is totally secure behind a firewall and other such things, always use roles. They are your last line of defense.
  2. Study and understand exactly how security groups work, in order to limit Inbound and Outbound.
  3. If you can, use the Elastic IP. It will save you many headaches if you move servers, not the least of which is that your IP will not change.
  4. When you gear up to a front facing Internet server, and Mongo behind it, be it with Sharding, Clusters etc. read up on the NAT gateway. It is confusing at first, but the NAT Gateway (not the NAT instance), is a decent setup in one configuration or another.
  5. Take snapshots or complete images of your environment when you change it. This is great for backup, and also when you move to a more robust server, it will save you a great deal of work.
  6. If you have not already, try using MongoBooster or RoboMongo. They will help you immensely with your Mongo work.

Good luck and enjoy!

twg
  • 1,075
  • 7
  • 11
1

The actual AWS implementation of MongoDB is DocumentDB, which from what i can tell is built on the opensource version of MongoDB version 3.6, so newer MongoDb features are/might/will not be supported.

An interesting article comparing DocumentDb with MongoDb Atlas(mongoDm cloud solution): https://medium.com/@michaelrbock/nosql-showdown-mongodb-atlas-vs-aws-documentdb-5dfb00317ca2

In the end if you really want MongoDB on AWS my opinion is you should just install it on a EC2 machine, I've done it via DocumentDB and some mongodb commands don't work, or chose AWS own NOSQL solution DynamicDB instead, DocumentDB just seems to be up there for competition with MongoDB Atlas cloud solution or just for having some dedicated MongoDB for companies that use it and want to move to AWS.

sergiu
  • 1,429
  • 1
  • 12
  • 8
0

You have different alternatives. To answer your question: yes, you can do it that way. But, there is also an official guide by Amazon to set up a MongoDB cluster on AWS.

Also, if you only need a NoSQL database, you should also check DynamoDB, developed by Amazon. That would eliminate the need of an EC2 instance for the database. For more info, check the official docs.

  • 1
    Thanks for that. Very helpful. I'm new to AWS so just getting my head around it... Follow up question... If I do go ahead and create a DB in my EC2 instance what would be the pros and cons of doing that? Would it be less reliable when scaling for lots of users etc? –  Mar 26 '17 at 01:38
  • If your are wondering specifically on the pros and cons of MongoDB vs DynamoDB, check [this SO question](https://stackoverflow.com/questions/17931073/dynamodb-vs-mongodb-nosql). If you are wondering the pros of using EC2 for your DB, you could check out the EC2 section of [this article](http://www.dbta.com/Columns/Next-Gen-Data-Management/To-RDS-or-EC2-Where-Will-Your-Database-Be-Happier-102958.aspx). – Benjamin Diaz Mar 26 '17 at 01:51