This commit is contained in:
Telesphoreo 2020-10-27 23:47:02 -05:00
parent 7d2e5c4b4a
commit b5ecd35e80

View File

@ -1,9 +1,10 @@
package me.totalfreedom.plex.storage; package me.totalfreedom.plex.storage;
import com.mongodb.MongoClient; import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientURI; import com.mongodb.client.MongoClients;
import dev.morphia.Datastore; import dev.morphia.Datastore;
import dev.morphia.Morphia; import dev.morphia.Morphia;
import dev.morphia.mapping.MapperOptions;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
@ -26,10 +27,9 @@ public class MongoConnection
String database = plugin.config.getString("data.central.db"); String database = plugin.config.getString("data.central.db");
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database; String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
MongoClient client = new MongoClient(new MongoClientURI(connectionString)); MongoClient client = MongoClients.create(connectionString);
Morphia morphia = new Morphia(); Datastore datastore = Morphia.createDatastore(client, database, MapperOptions.DEFAULT);
Datastore datastore = morphia.createDatastore(client, database); datastore.getMapper().map(PlexPlayer.class);
datastore.getMapper().addMappedClass(PlexPlayer.class);
datastore.ensureIndexes(); datastore.ensureIndexes();
plugin.setStorageType(StorageType.MONGO); plugin.setStorageType(StorageType.MONGO);
return datastore; return datastore;