MongoClient Class not working with Morphia? (Java)

So I’m trying to setup MongoDB with Morphia for Java, but when I try to pass in the MongoClient class, it says I am not using the correct version of this class.

I have tried editing the import to use the other class (com.mongodb.MongoClient instead of com.mongodb.client.MongoClient) but that breaks the rest of the code, and casting throws an error as well. Also can’t find this error anywhere online.

Does anyone have any ideas on what could be going on here

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import lombok.Getter;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
public PlayerDataManager() {

        //Setup the MongoDB Connection
        ConnectionString connectionString = new ConnectionString("xxxxxxxxx"); //This does work btw, have tested
        MongoClientSettings settings = MongoClientSettings.builder()
                .applyConnectionString(connectionString)
                .build();
        try {
            client = MongoClients.create(settings);

            morphia = new Morphia();
            morphia.map(PlayerData.class);
            playerDataStore = morphia.createDatastore(client, "playerdata");
            playerDataStore.ensureIndexes();

            playerDataDAO = new PlayerDataDAO(PlayerData.class, playerDataStore);
        }
        catch (NoClassDefFoundError e) {
            e.printStackTrace();
        }
    }
1 Like

How did you solve this?