ConnectionString class not found

When I try to run my Gradle project it gives the java.lang.NoClassDefFoundError: com/mongodb/ConnectionString error, I added org.mongodb:mongodb-driver-sync:4.8.1 as a dependency and my IntelliJ isn’t giving any errors. Anyone ran into this problem before? Here’s my code:

        ConnectionString connectionString = new ConnectionString("");
        MongoClientSettings settings = MongoClientSettings.builder()
        MongoDatabase database = MongoClients.create(settings).getDatabase("test");
        MongoCollection<Document> collection = database.getCollection("test");

(Connection string is correct, I just didn’t want to leak it)

Hello @Jonathan_Jackson ,

Welcome to The MongoDB Community Forums! :wave:

I believe the most common reason for this error is that it can’t find the class that connects to MongoDB, perhaps you’re missing some imports or classpath?

If the issue you’re trying to solve is connecting to MongoDB, you might want to check the code examples in Java sync - Connect to MongoDB and see if it works for you.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.