Java cannot connect MongoDB problem __java

Source: Internet
Author: User
Tags mongodb ssh

Background information:

Because the Linux server used for development is in a relatively closed environment, only 22 ports are accessed via SSH. So I used putty to do an SSH forwarding to map the 27018 port of this machine to the remote 27017 port. Successfully connected via MONGO localhost:27018 in CMD and operated.


Phenomenon:

In the program through the

Mongo Mongo = new Mongo ("localhost", 27018);
MongoDB on a remote server, the following error occurred while the program was running:

caused By:java.io.IOException:couldn ' t connect to [3cnl07745/172.28.220.64:27018] Bc:java.net.ConnectException: Connection Refused:connect at
	Com.mongodb.dbport._open (dbport.java:206) at
	Com.mongodb.DBPort.go ( dbport.java:94) at
	com.mongodb.DBPort.go (dbport.java:75) at
	Com.mongodb.DBPort.call (dbport.java:65)
	At Com.mongodb.DBTCPConnector.call (dbtcpconnector.java:207) ...
	Panax Notoginseng

As seen from the exception information, localhost is replaced with a "machine name/IP address", which is not connected in CMD.


Workaround:

In fact, the solution is quite simple: replace the localhost to become 127.0.0.1 .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.