Dockerizing Express-MongoDB Atlas (docker-compose) - node.js

My apologies if this is a noob question but, is it possible to configure a docker-compose file to get an already-existing Mongo Atlas database working as part of a docker network?
I have searched in internet but everyone is using new local mongodb connections or new mongodb Atlas ones.
(I have an express node forum running and its hosted on Atlas cloud db)

First of all you need to understand that MongoDB Atlas is a Cloud platform for MongoDB, so the database lives somewhere in the cloud, e.g. AWS.
While Docker network is a local network that Docker creates for you to encapsulate different containers into one net, thus making it possible to communicate between each other, and by the same token be isolated from world.
The answer is that you cannot make MongoDB Atlas part of your Docker network, because Atlas is not a Container that you could embed into your network. But the good news that you don't need to, because you can connect to the Atlas instance anyways from any computer, in condition that configuration of your Atlas allows to establish connections.

Related

Mongo db replication using node js

I am new to MongoDB and NodeJS. I am running an ec2 instance on AWS and I want to sync the data of AWS to local systems and local to AWS. I don't have any idea about how to do it. I have tried some configuration in database files but I am not able to connect my local system with remote server.
I found this repository on git hub https://github.com/sheharyarn/mongo-sync but I don't know how to use that repository in my code.
Kindly help me.
Thank you
Mongodb atlas provides free 512MB of space. You can create cluster in mongoldb atlas and use online database from anywhere. it will work on your local machine and also on aws server.
Just open mongoldb website you can find mongoldb atlas easily. after sign up.

Using same EC2 instance for node and mongo hosting

Can I use my aws EC2 instance to run both node server and mongo server by installing mongo driver into my EC2 instance ?
Its gotta be just like how we do it in our localhost, right?
I'd rather advise you to separate concerns and have dedicated instances for nodejs and for mongodb. It's not only good practice to separate app and db but also you'll able to scale much easier, and you'll scale exactly what you need.

Mongoerror: failed to connect to server localhost:27017 on first connect

I have created an application using MEAN, After that, I have created the ec2 Linux instance, where I am running this application.I have installed all the dependencies.
Added port 27017 on security group page.
running the command on the ec2 instance as node server.js
Node: My mongo DB is outside my cloud instance i.e on my laptop.
How can I fix this error?
You need to open your laptop to internet which is almost impossible (and you shouldn't). That means you need a MongoDB server which is accessible by your EC2 Linux instance.
You may use a free mongodb hosting such as mlab
On the other hand you can enable another EC2 instance and setup your own mongodb. Beware that you may need to setup firewall if it's not an internal network.

Scaling a two-tier MEAN application with Docker on AWS

So my current set-up is a Node.js application that serves up an Angular front-end, a second Node.js application that has Express and serves as an API, and a MongoDB instance. Simply, the client-side app talks to the back-end app and the back-end app talks to MongoDB.
I was looking into how to Dockerize these applications and it seems like some examples use linking. So my question is does linking only work on the same host (meaning a single EC2 instance on AWS) or multiple EC2 instances? If only the former and if I have both apps and Mongo containerized on one instance, how do I scale out? Like if I spin up a second EC2 instance, would I put both containerized Node apps and Mongo again on that second instance? Is having a Mongo container on the same instance with the Node apps a single point of failure? How is that fault tolerant?
Just trying to wrap my head around this and apologize for my ignorance on the subject. Thanks!
You should put each app as well as the MongoDB server in separate containers (which is what I think you intend) and the linking (via Docker-Compose or other method) is just networking. If you use Docker links, it creates a private network. You can create other networks to talk to each other, also to a LAN, WAN, whatever.
Yes, putting them all on the same EC2 instance is creating a SPOF.
If that's a concern, look into: https://docs.docker.com/swarm/networking/
Docker Swarm is fully compatible with Docker’s networking features.
This includes the multi-host networking feature which allows creation
of custom container networks that span multiple Docker hosts.
Or load balance your apps and use an AWS-hosted MongoDB cluster. There are many possible approaches based on your needs and budget.

Using MongoDB with AWS ElasticBean application

I have an ElasticBean application running (setup with NodeJS) and I wondered what the best way to integrate MongoDB would be. As of now, all I've done is ssh into my eb instance (with the eb cli) and install mongodb. My main worry comes from the fact that the mongo db exists in my instance. As I understand it, that means that my data will most certainly be lost as soon as I terminate my instance. Is that correct? If so the what is the best way to go about hooking en EB app to a MongoDB? Does AWS support that natively without having to go rent a DB on a dedicated server?
You definitely do NOT want to install MongoDB on an Elastic Beanstalk instance.
You have a few options for running MongoDB on AWS. You can install it yourself on some EC2 servers (NOT Elastic Beanstalk servers) and handle all the management of that yourself. The other option is to use mLab (previously MongoLab) which is a managed MongoDB as a Service provider that works on AWS as well as other cloud services. Using mLab you can easily provision a MongoDB database in the same AWS region as your Elastic Beanstalk servers.
Given the steps involved in setting up a highly-available MongoDB cluster on AWS I generally recommend using mLab instead of trying to handle it yourself. Just know that the free-tier is not very performant and you will want to upgrade to one of the paid plans for your production database.
Been there, done that. As #MarkB suggested it´d be a lot easier to use a SaaS instead.
AWS by itself doesn´t have a native MongoDB support but deppending of your requierements you could find a solution with little or no extra cost (beside EC2 price) on Amazon Marketplace. These images are vendor´s pre-configured production-ready AMIs of popular tools like MongoDB.

Resources