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.
The communication between the ngrok edge and agent is secure and encrypted. Traffic from the user to the ngrok edge, and from the ngrok agent to the upstream service rely on the protocol you are using for encryption. For protocols that support end to end encryption using TLS, we provide a TLS tunnel option.
FTP Server: ngrok tcp 21. SFTP Server: ngrok tcp 22.
MongoDB uses TCP
not HTTP
.
ngrok tcp 27017
(note the tcp
, not http
which I think is what you used)
There are a couple of extra steps you need to do for some reason when you use TCP, and ngrok will prompt you and tell you what you need to do when you try the above command.
ngrok authtoken 123ABC456ETC
)ngrok tcp 27017
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With