Link to home
Start Free TrialLog in
Avatar of VBBRett
VBBRett

asked on

Need to connect to MonoDB on AWS server with user is and password

I am trying to connect to a MongoDB database with asp.net core in C# with a userid and password.  Can anyone assist me in that respect?
Avatar of David Favor
David Favor
Flag of United States of America image

You have to debug this systematically.

The following is a very terse explanation.

Summary: Make sure you can connect locally, then wrap your MongoDB remote connections in TLS, then retest.

1) ssh into your AWS instance.

2) Install the https://docs.mongodb.com/manual/mongo/ command line client.

3) Ensure you can connect to your MongoDB instance, using user/pass you setup at installation time.

4) Open your MongoDB client port to public connections via your firewall system (usually iptables).

5) Setup your MongoDB instance using https://ianlondon.github.io/blog/mongodb-auth/ for remote connections on 127.0.0.1 (so really local connections).

6) Test again with MongoDB client.

7) Use https://docs.mongodb.com/manual/tutorial/configure-ssl-clients/ instructions to wrap your non-127.0.0.1 connections with an SSL cert.

8) Add your public IP to #5 setup + force to only allow remote connections via TLS.

9) Now install the MongoDB command line client on a remote machine.

10) Test your remote TLS connections.
All this is fairly straight forward, if you do this type of setup every day.

If it's you're first time, you might prefer to hire someone + have them document all the steps for you.
Avatar of VBBRett
VBBRett

ASKER

Thank you David, but I was already past that point initially.  I was able to access the MongoDB using Studio 3T and the Mongo Compass platform.  What I'm looking for is how to access a remote MongoDB using crednetials(username and password) in C# with a non-local MongoDB.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.