How to connect to remote MongoDB hosted on an AWS EC2 instance?

You can follow the below steps to connect to MongoDB hosted on an AWS EC2 instance.

Step 1: Connect to your AWS EC2 instance over SSH.

Step 2: Open mongo shell by typing mongo in the EC2 terminal

Step 3: Create a new user and give the user access to your MongoDB database.

Step 4: Update the mongo configuration file to allow remote connection.

Step 5: Open port 27017 on your EC2 instance security group inbound rule.

Step 6: Restart MongoDB service

Step 7: Now from your local system, try to connect to MongoDB remotely.