Answer the question
In order to leave comments, you need to log in
Error connecting to MongoDB. How to fix?
I am trying to connect to mongodb:
MongoClient mongoClient = MongoClients.create("mongodb link");
MongoDatabase database = mongoClient.getDatabase("testdb");
MongoCollection<Document> paidsCollection = database.getCollection("test");
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.7</version>
</dependency>
Answer the question
In order to leave comments, you need to log in
There is no MongoClients class (with an s at the end) in the MongoDB Driver for Java. There is a MongoClient class.
So, you need to write like this:
MongoClient mongoClient = MongoClient.create("mongodb link");
import com.mongodb.client.MongoClients
, delete it, it's not right. MongoClient mongoClient = new MongoClient("mongodb link");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question