I have a MongoDb hosted locally in my machine and runs successfully in port localhost:27017. The database has a user name and password with a collection named, "testDb". In the code, I am able to access the database successfully using localhost.
I am trying to access this MongoDb from a remote desktop using ngrok. I hace implemented the port forwarding and the following response is shown in the command prompt.
Forwarding https://5e825c82.ngrok.io -> http://localhost:27017
I also tried changing the port => Forwarding https://5e825c82.ngrok.io -> http://localhost:28017
Both ports failed with the following Error message: The connection to http://5e825c82.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:28017. Make sure that a web service is running on localhost:28017 and that it is a valid address. The error encountered was: dial tcp [::1]:28017: connectex: No connection could be made because the target machine actively refused it.
// Works fine
MongoClient client = new MongoClient("mongodb://admin:admin@localhost:27017/testDb");
// Fails:
MongoClient client = new MongoClient("mongodb://admin:[email protected]/testDb");
I would like to know how to establish a connection to the MongoDb with ngrok.