I have a problem with my MongoDB in Java. I cannot connect to it I always get an exception and could not resolve it. I use Maven Dependencies for that. I tried using other versions of the dependency.
I also checked that the MongoDB is running. I started it with net start MongoDB. My code:
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
public class MongoDBTest {
public static void main(String[] args) throws Exception {
MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://127.0.0.1:27017"));
}
}
My dependency:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.10.0</version>
</dependency>
And the exception i got:
Exception in thread "main" java.lang.NoSuchMethodError: com.mongodb.ConnectionString.getThreadsAllowedToBlockForConnectionMultiplier()Ljava/lang/Integer;
at com.mongodb.MongoClientURI.getOptions(MongoClientURI.java:351)
at com.mongodb.Mongo.createCluster(Mongo.java:724)
at com.mongodb.Mongo.<init>(Mongo.java:312)
at com.mongodb.Mongo.<init>(Mongo.java:308)
at com.mongodb.MongoClient.<init>(MongoClient.java:326)
at schlueting.arbeiten.MongoDBTest.main(MongoDBTest.java:9)