I am trying to connect MongoDB with Java. This is my code
MongoCredential mongoCredential;
mongoCredential = MongoCredential.createCredential(<uname>, <dbname>, <password>);
List<ServerAddress> list = Arrays.asList(new ServerAddress("localhost", 27017));
MongoClientSettings.Builder mongoClientSettingsBuilder = MongoClientSettings.builder()
.credential(mongoCredential)
.applyToClusterSettings(builder -> builder.hosts(list));
MongoClientSettings settings = mongoClientSettingsBuilder.build();
Executing this I get the error
Exception in thread "main" java.lang.NoSuchMethodError: com.mongodb.connection.DefaultClusterFactory.createCluster(Lcom/mongodb/connection/ClusterSettings;Lcom/mongodb/connection/ServerSettings;Lcom/mongodb/connection/ConnectionPoolSettings;Lcom/mongodb/connection/StreamFactory;Lcom/mongodb/connection/StreamFactory;Ljava/util/List;Lcom/mongodb/event/CommandListener;Ljava/lang/String;Lcom/mongodb/MongoDriverInformation;Ljava/util/List;)Lcom/mongodb/connection/Cluster;
I do not know what is the reason for this. Can someone help me out with this