Java Connection MongoDB Error resolution

Source: Internet
Author: User
Tags mongodb

Error content

Com.mongodb.MongoTimeoutException:Timed out after 30000 MS and waiting for a server that matches Readpreferenceserverse Lector{readpreference=primary}. Client view of cluster state is {type=unknown, servers=[{address=127.0.0.1:27017, Type=unknown, state=connecting, Exception={com.mongodb.mongosocketopenexception:exception opening Socket}, caused by {java.net.ConnectException: Connection Refused:connect}}]

This means that the connection is not successful, 127.0.0.1 this is local, but the IP 192.168.xx.xx of the Linux virtual machine

So the Linux connection is not the same as the Java connection, all to the same IP.

1. If Linux is not set to IP, the default is 127.0.0.1, but the Linux IP is not this, all Java connections are not

The solution is to set the MongoDB boot IP to LINUXIP

1. When you start, you can add IP--bind_ip=192.168.88.134 directly to the rear.

/home/mongodb/bin/mongod--fork--bind_ip=192.168.88.134--dbpath=/home/mongodb/data/db--logpath=/home/mongodb/ Data/log/mongodb.log--logappend

2. Create a mongodb.conf file yourself, put the values to be set inside, I only put a few major tests

# log file location logpath=/usr/local/server/mongodb/logs# write to log logappend=true# as a daemon run fork = true# default 27017port = 27017# Database file location Dbpath=/usr/local/server/mongodb/data#ip address bind_ip = 127.0.0.1

The configuration file will be added to boot.

./mongod--config/usr/local/server/mongodb/mongodb.conf

Java Connection MongoDB Error resolution

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.