spring An error was reported when the boot project started to connect mongodb.
2021-06-09 17:10:34,663 INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server node1:27017
com.mongodb.MongoSocketException: node1
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:211)
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:75)
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: node1
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203)
... 5 common frames omitted
Because it’s a new project, Mongo library belongs to other projects. This is just a test application. So the first doubt is that the project version driver is not compatible with mongodb library. After replacing other versions of mongodb library, it is OK.
Detailed explanation
View the
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
Because of spring Mongodb driver is also the official driver of encapsulated mongodb. When you enter the spring data mongodb project, you can see that the official version of mongodb driver is 3.8.2
Then go to the official website of mongodb to see that version 3.8 supports version 4.0 database at most. I started testing with the 4.2 library (Official website https://docs.mongodb.com/drivers/java/)
So that’s it.
Read More:
- MongoDB:Failed: error connecting to db server: no reachable servers
- Solve the problem that the local flow of the nifi node is inconsistent with the cluster flow, resulting in the failure to join the cluster
- The solution of a Java exception has occurred. And error exception in thread when eclipse runs
- java.lang.ClassNotFoundException : com.mysql.jdbc . driver project cannot connect to database, exception, lack of MySQL driver
- Window installation of MongoDB exception: connect failed exception
- Realize the simplest recursive call, simulate exception in thread “main” java.lang.stackoverflowerror exception
- Python error unhandled exception in thread started by error in sys.excepthook
- 530 user cannot log in. Problem connecting to FTP server
- Mongodb uses Mongo to report error: could’t connect to server 127.0.0.1:27017, connection attempt failed: socket
- The mongoDB service failed to start (exception: connect failed)
- [Solved] Mac ES Startup Error: Exception in thread “main“ java.nio.file.NotDirectoryException
- Exception in thread “main“ java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to XXX
- Error when connecting to database: DB2 SQL error: sqlcode = – 204, sqlstate = 42704, sqlerrmc= YXUAT.CUST_ BLK_ REL, DRIVER=4.25.13
- When setting up etcd cluster, an error is reported. Etcd: request cluster ID mismatch error resolution is only applicable to new etcd cluster or no data cluster
- How to Fix Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
- How to Fix error performing isolated work; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarE
- Error: Exception was raised when calling per-thread-terminate function in extension lrwreplaymain.dl
- Failed: error connecting to db server: server returned error on SASL authentication step: Authentica
- MongoDB Error: Failed to start mongod.service: Unit mongodb.service is masked
- Mongodb — startup exception, error report ERROR:NUMBER 100