How to connect to MongoDB hosted on Google Cloud - node.js

I just created a MongoDB instance on Google Cloud.
I have been using mLab for my purpose and I was able to connect to that DB using IPAddress: PORT and user/password combination.
How to connect to MongoDB instance using IP Address and port number? Where can I find these details in my VM Instance?
I also want to connect to same DB through my NodeJS app using mongoose. How can I do that?

Related

Connect MongoDB to NodeJS on GAE

I'm running a NodeJS app on GAE and I want to connect to a mongodb cluster on Atlas.
I have white-listed my IP on atlas and established a connection. All work fine on my local machine.
When deployed my app on GAE it could not connect to Atlas since the IP is not white-listed. When I white-listed all IPs on Atlas I could make a connection and everything worked fine as on my local machine
I cannot assign a static-IP to a standard GAE app, therefore I must allow access from anywhere to my cluster on Atlas, which is probably a bad idea.
What would be best solution to work with mongoDB from a GAE standard app?
Any configuration I can make to Atlas? maybe switching to mLab? or any other ideas?
App Engine applications do not have fixed IP addresses. I'm not very familiar with MongoDB Atlas, but it does look like it offers an option to run on GCP and if that runs on a Compute Engine instance what you might be able to do is use the VPC Connector to enable access between your app and your MongoDB setup.

How to connect my Heroku hosted Node REST services to remote SQL?

Can anyone please tell me about how to connect REST based services on Heroku to a Linux based Remote SQL?
I'm new to hosting REST based services. I've created some REST services via Node.js and Express and I'm trying to connect those services with a remote SQL database on my hosting plan on https://ecowebhosting.co.uk.
But it always shows server closed the connection because it requires an IP address to setup a connection between server and heroku.

Unable to connect Node app hosted on Heroku with MongoDB Cluster

i am making NodeJS app hosted on heroku and using MongoDB atlas as a backend.When i am sending POST request to app via POSTMAN it is showing:
Error: 503 service unavailable
In my opinion node app is failed to connect with MongoDB atlas cluster.If so then how can i connect it with MongoDB.
THANKS
See Connecting Heroku App to Atlas MongoDB Cloud service, you need to either connect via SSL or whitelist the relevant Heroku IP address ranges for your app.

Connection Node app with MongoDB hosted in a Droplet

I am now trying to host my Angular, Node, MongoDB app on DigitalOcean. I have succesfully set up the two Droplets, one for Node Backend and one for MongoDB Database. Until now I was using a local link to connect to local database like the following link mongodb://localhost:27017/creditApp .
How do I connect my Node app hosted in Droplet to the MongoDB hosted in another Droplet? The database has admin password set up, also has allowed the IP address from my backend in the ufw list. I assume it needs a config object with admin name, password, ssh key .pub file etc and attach that object while trying to connect it, but I am not quite sure how to do it. How do I get this done?
Any help will be highly appreciated, thanks in advance.

Connecting to Mongodb Amazon EC2 instance programmatically in Nodejs

I am making a NodeJS webapp. I would like to deploy the app using Amazon's elastic beanstalk and I would like to use MongoDB as the database. Right now my understanding of a solution is to:
Set up a MongoDB instance on an Amazon EC2 instance (I've already done this)
Connect to this database programmatically in server.js to read and write to the database
Does this solution make sense? If so, how do I connect to the EC2 MongoDB instance programmatically?
I've found the official MongoDB package for node:https://www.npmjs.com/package/mongodb
but the documentation only mentions connecting to a local instance of MongoDB:
// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server");
db.close();
});
Current I am able to ssh into my EC2 MongoDB instance but I don't understand how to take the next step and connect to it programmatically.
When I ssh into the EC2 MongoDB instance, I need to provide a .pem key file, do I need to do something similar when I connect programmatically?
As per your use case your Mongodb is local on a EC2 instance. So when you connect to Mongodb you will have to SSH using a pem key to EC2 instance in order to connect to the Mongodb. If you want to avoid using pem key each time, you can create a SSH user which can SSH to instance using UN and password.
This is helpful guide to achieve it:
https://coderwall.com/p/j5nk9w/access-ec2-linux-box-over-ssh-without-pem-file
Or another way is connecting using the SSH key.
No, you don't need a .pem key for connecting to MongoDB instance.
Make sure your Ec2 instance has a public domain or IP. This IP can be used in place of localhost in your node DB configuration.
The mongo server should be running on the instance. Check mongo shell to confirm.
Create a VPC for better management of instance and define security group with required ports.
Use security credentials in your database configuration file.
I would suggest to always have a private IP for database instances and the instance on which your HTTP server is running should have public IP which is mapped with DNS provider. Open minimum ports on DB server mainly :27017 which makes it secure. Both the instances should be inside once VPC since private IP's are only accessible here.

Resources