diff --git a/build.gradle.kts b/build.gradle.kts index 23e36554..3de49a0e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -64,7 +64,8 @@ dependencies { implementation(libs.github.api) // KMongo - implementation(libs.kmongo) + //implementation(libs.kmongo) + implementation(libs.mongo.driver) // Cozy's welcome module implementation(libs.cozy.welcome) diff --git a/libs.versions.toml b/libs.versions.toml index 62ed2b78..91fd6cad 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -13,6 +13,7 @@ logging = "5.1.0" logback = "1.4.9" github-api = "1.315" kmongo = "4.9.0" +mongo-driver = "4.10.1" cozy-welcome = "1.0.1-SNAPSHOT" dma = "v0.2.1" docgenerator = "0.1.2-SNAPSHOT" @@ -27,6 +28,7 @@ logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } logging = { module = "io.github.oshai:kotlin-logging", version.ref = "logging" } github-api = { module = "org.kohsuke:github-api", version.ref = "github-api" } kmongo = { module = "org.litote.kmongo:kmongo-coroutine-serialization", version.ref = "kmongo" } +mongo-driver = { module = "org.mongodb:mongodb-driver-kotlin-coroutine", version.ref = "mongo-driver" } detekt = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt"} cozy-welcome = {module = "org.quiltmc.community:module-welcome", version.ref = "cozy-welcome"} dma = { module = "org.hyacinthbots:discord-moderation-actions", version.ref = "dma"} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt index 7d5671ac..d7c29e91 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt @@ -1,10 +1,12 @@ package org.hyacinthbots.lilybot.database import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters import dev.kord.core.Kord import dev.kord.core.behavior.getChannelOfOrNull import dev.kord.core.entity.channel.thread.ThreadChannel import dev.kord.rest.request.KtorRequestException +import kotlinx.coroutines.flow.toList import kotlinx.datetime.Clock import mu.KotlinLogging import org.hyacinthbots.lilybot.database.Cleanups.cleanupGuildData @@ -24,7 +26,6 @@ import org.hyacinthbots.lilybot.database.collections.WelcomeChannelCollection import org.hyacinthbots.lilybot.database.entities.GuildLeaveTimeData import org.hyacinthbots.lilybot.database.entities.ThreadData import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This object contains the Database clean up functions, for removing old data from the database that Lily no longer @@ -38,10 +39,10 @@ object Cleanups : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val guildLeaveTimeCollection = db.mainDatabase.getCollection() + internal val guildLeaveTimeCollection = db.mainDatabase.getCollection("guildLeaveTimeData") @PublishedApi - internal val threadDataCollection = db.mainDatabase.getCollection() + internal val threadDataCollection = db.mainDatabase.getCollection("threadData") @PublishedApi internal val cleanupsLogger = KotlinLogging.logger("Database Cleanups") @@ -75,7 +76,8 @@ object Cleanups : KordExKoinComponent { UtilityConfigCollection().clearConfig(it.guildId) WarnCollection().clearWarns(it.guildId) WelcomeChannelCollection().removeWelcomeChannelsForGuild(it.guildId, kord) - guildLeaveTimeCollection.deleteOne(GuildLeaveTimeData::guildId eq it.guildId) + val leaveFilters = Filters.eq(GuildLeaveTimeData::guildId.name, it.guildId) + guildLeaveTimeCollection.deleteOne(leaveFilters) deletedGuildData += 1 // Increment the counter for logging } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt index 01e2d82c..392c4f91 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt @@ -2,11 +2,10 @@ package org.hyacinthbots.lilybot.database import com.mongodb.ConnectionString import com.mongodb.MongoClientSettings +import com.mongodb.kotlin.client.coroutine.MongoClient import org.bson.UuidRepresentation import org.hyacinthbots.lilybot.database.migrations.Migrator import org.hyacinthbots.lilybot.utils.MONGO_URI -import org.litote.kmongo.coroutine.coroutine -import org.litote.kmongo.reactivestreams.KMongo class Database { // Connect to the database using the provided connection URL @@ -16,7 +15,7 @@ class Database { .applyConnectionString(ConnectionString(MONGO_URI)) .build() - private val client = KMongo.createClient(settings).coroutine + private val client = MongoClient.create(settings) /** The main database for storing data. */ val mainDatabase get() = client.getDatabase("LilyBot") diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt new file mode 100644 index 00000000..944a8ca8 --- /dev/null +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt @@ -0,0 +1,19 @@ +package org.hyacinthbots.lilybot.database + +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Filters.and +import com.mongodb.kotlin.client.coroutine.FindFlow +import com.mongodb.kotlin.client.coroutine.MongoCollection +import kotlinx.coroutines.flow.firstOrNull +import org.bson.conversions.Bson + +private fun MongoCollection.find(vararg filters: Bson?): FindFlow = find(and(*filters)) + +suspend fun MongoCollection.findOne(filter: Bson): T? = find(filter).firstOrNull() + +suspend fun MongoCollection.findOne(vararg filters: Bson?): T? = + find(*filters).firstOrNull() + +suspend fun MongoCollection.deleteOne() = deleteOne(Filters.empty()) + +// TODO Make more cool useful functions diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt index db1c6104..fb65eff4 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.AutoThreadingData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [AutoThreading Database][AutoThreadingData]. This @@ -22,7 +24,7 @@ class AutoThreadingCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("autoThreadingData") /** * Gets all auto threads for a given [inputGuildId]. @@ -33,7 +35,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun getAllAutoThreads(inputGuildId: Snowflake): List = - collection.find(AutoThreadingData::guildId eq inputGuildId).toList() + collection.find(eq(AutoThreadingData::guildId.name, inputGuildId)).toList() /** * Gets a single auto thread based off the channel ID. @@ -44,7 +46,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun getSingleAutoThread(inputChannelId: Snowflake): AutoThreadingData? = - collection.findOne(AutoThreadingData::channelId eq inputChannelId) + collection.findOne(eq(AutoThreadingData::channelId.name, inputChannelId)) /** * Sets a new auto thread. @@ -54,7 +56,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun setAutoThread(inputAutoThreadData: AutoThreadingData) { - collection.deleteOne(AutoThreadingData::channelId eq inputAutoThreadData.channelId) + collection.deleteOne(eq(AutoThreadingData::channelId.name, inputAutoThreadData.channelId)) collection.insertOne(inputAutoThreadData) } @@ -66,7 +68,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun deleteAutoThread(inputChannelId: Snowflake) = - collection.deleteOne(AutoThreadingData::channelId eq inputChannelId) + collection.deleteOne(eq(AutoThreadingData::channelId.name, inputChannelId)) /** * Deletes auto threads for a given guild. @@ -76,5 +78,5 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun deleteGuildAutoThreads(inputGuildId: Snowflake) = - collection.deleteMany(AutoThreadingData::guildId eq inputGuildId) + collection.deleteMany(eq(AutoThreadingData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt index 61752bca..f83e1e10 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt @@ -1,13 +1,14 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.LoggingConfigData import org.hyacinthbots.lilybot.database.entities.ModerationConfigData import org.hyacinthbots.lilybot.database.entities.UtilityConfigData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Logging Config Database][LoggingConfigData]. This class @@ -22,7 +23,7 @@ class LoggingConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection() + internal val collection = configDb.configDatabase.getCollection("loggingConfigData") /** * Gets the logging config for the given guild using the [guildId][inputGuildId]. @@ -33,7 +34,7 @@ class LoggingConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun getConfig(inputGuildId: Snowflake): LoggingConfigData? = - collection.findOne(LoggingConfigData::guildId eq inputGuildId) + collection.findOne(eq(LoggingConfigData::guildId.name, inputGuildId)) /** * Adds the given [loggingConfig] to the database. @@ -43,7 +44,7 @@ class LoggingConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun setConfig(loggingConfig: LoggingConfigData) { - collection.deleteOne(LoggingConfigData::guildId eq loggingConfig.guildId) + collection.deleteOne(eq(LoggingConfigData::guildId.name, loggingConfig.guildId)) collection.insertOne(loggingConfig) } @@ -55,7 +56,7 @@ class LoggingConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun clearConfig(inputGuildId: Snowflake) = - collection.deleteOne(LoggingConfigData::guildId eq inputGuildId) + collection.deleteOne(eq(LoggingConfigData::guildId.name, inputGuildId)) } /** @@ -71,7 +72,7 @@ class ModerationConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection() + internal val collection = configDb.configDatabase.getCollection("moderationConfigData") /** * Gets the Moderation config for the given guild using the [guildId][inputGuildId]. @@ -82,7 +83,7 @@ class ModerationConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun getConfig(inputGuildId: Snowflake): ModerationConfigData? = - collection.findOne(ModerationConfigData::guildId eq inputGuildId) + collection.findOne(eq(ModerationConfigData::guildId.name, inputGuildId)) /** * Adds the given [moderationConfig] to the database. @@ -92,7 +93,7 @@ class ModerationConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun setConfig(moderationConfig: ModerationConfigData) { - collection.deleteOne(ModerationConfigData::guildId eq moderationConfig.guildId) + collection.deleteOne(eq(ModerationConfigData::guildId.name, moderationConfig.guildId)) collection.insertOne(moderationConfig) } @@ -104,7 +105,7 @@ class ModerationConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun clearConfig(inputGuildId: Snowflake) = - collection.deleteOne(ModerationConfigData::guildId eq inputGuildId) + collection.deleteOne(eq(ModerationConfigData::guildId.name, inputGuildId)) } /** @@ -120,7 +121,7 @@ class UtilityConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection() + internal val collection = configDb.configDatabase.getCollection("utilityConfigData") /** * Gets the Utility config for the given guild using the [guildId][inputGuildId]. @@ -131,7 +132,7 @@ class UtilityConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun getConfig(inputGuildId: Snowflake): UtilityConfigData? = - collection.findOne(UtilityConfigData::guildId eq inputGuildId) + collection.findOne(eq(UtilityConfigData::guildId.name, inputGuildId)) /** * Adds the given [utilityConfig] to the database. @@ -141,7 +142,7 @@ class UtilityConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun setConfig(utilityConfig: UtilityConfigData) { - collection.deleteOne(UtilityConfigData::guildId eq utilityConfig.guildId) + collection.deleteOne(eq(UtilityConfigData::guildId.name, utilityConfig.guildId)) collection.insertOne(utilityConfig) } @@ -153,5 +154,5 @@ class UtilityConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun clearConfig(inputGuildId: Snowflake) = - collection.deleteOne(UtilityConfigData::guildId eq inputGuildId) + collection.deleteOne(eq(UtilityConfigData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt index c9b75e79..0784c0b1 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt @@ -1,12 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.GalleryChannelData import org.koin.core.component.inject -import org.litote.kmongo.coroutine.CoroutineCollection -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Gallery Channel Database][GalleryChannelData]. This @@ -22,17 +23,17 @@ class GalleryChannelCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("galleryChannelData") /** * Collects every gallery channel in the database into a [List]. * - * @return The [CoroutineCollection] of [GalleryChannelData] for all the gallery channels in the database + * @return The [MongoCollection] of [GalleryChannelData] for all the gallery channels in the database * @author NoComment1105 * @since 3.3.0 */ suspend inline fun getChannels(inputGuildId: Snowflake): List = - collection.find(GalleryChannelData::guildId eq inputGuildId).toList() + collection.find(eq(GalleryChannelData::guildId.name, inputGuildId)).toList() /** * Stores a channel ID as input by the user, in the database, with it's corresponding guild, allowing us to find @@ -56,8 +57,10 @@ class GalleryChannelCollection : KordExKoinComponent { */ suspend inline fun removeChannel(inputGuildId: Snowflake, inputChannelId: Snowflake) = collection.deleteOne( - GalleryChannelData::channelId eq inputChannelId, - GalleryChannelData::guildId eq inputGuildId + and( + eq(GalleryChannelData::channelId.name, inputChannelId), + eq(GalleryChannelData::guildId.name, inputGuildId) + ) ) /** @@ -68,5 +71,5 @@ class GalleryChannelCollection : KordExKoinComponent { * @since 4.1.0 */ suspend inline fun removeAll(inputGuildId: Snowflake) = - collection.deleteMany(GalleryChannelData::guildId eq inputGuildId) + collection.deleteMany(eq(GalleryChannelData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt index 98732e2f..88a89bcc 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt @@ -1,11 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.GithubData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [GitHub database][GithubData]. This class contains @@ -20,7 +21,7 @@ class GithubCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("githubData") /** * Gets the default repo for GitHub commands. @@ -31,7 +32,7 @@ class GithubCollection : KordExKoinComponent { * @since 4.3.0 */ suspend inline fun getDefaultRepo(inputGuildId: Snowflake): String? = - collection.findOne(GithubData::guildId eq inputGuildId)?.defaultRepo + collection.findOne(eq(GithubData::guildId.name, inputGuildId))?.defaultRepo /** * Sets the default repo for GitHub commands. @@ -42,7 +43,7 @@ class GithubCollection : KordExKoinComponent { * @since 4.3.0 */ suspend inline fun setDefaultRepo(inputGuildId: Snowflake, url: String) { - collection.deleteOne(GithubData::guildId eq inputGuildId) + collection.deleteOne(eq(GithubData::guildId.name, inputGuildId)) collection.insertOne(GithubData(inputGuildId, url)) } @@ -54,5 +55,5 @@ class GithubCollection : KordExKoinComponent { * @since 4.3.0 */ suspend inline fun removeDefaultRepo(inputGuildId: Snowflake) = - collection.deleteOne(GithubData::guildId eq inputGuildId) + collection.deleteOne(eq(GithubData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt index 60b21c6b..3489de34 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt @@ -1,12 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import kotlinx.datetime.Instant import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.GuildLeaveTimeData import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Guild Leave Time Database][GuildLeaveTimeData]. This @@ -20,7 +20,7 @@ class GuildLeaveTimeCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("guildLeaveTimeData") /** * Adds the time Lily bot left a guild with a config. @@ -43,5 +43,5 @@ class GuildLeaveTimeCollection : KordExKoinComponent { * @since 3.2.0 */ suspend inline fun removeLeaveTime(inputGuildId: Snowflake) = - collection.deleteOne(GuildLeaveTimeData::guildId eq inputGuildId) + collection.deleteOne(eq(GuildLeaveTimeData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt index 01ae94aa..71c1cdb6 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt @@ -1,11 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.ConfigMetaData import org.hyacinthbots.lilybot.database.entities.MainMetaData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [main meta database][MainMetaData]. This class @@ -20,7 +21,7 @@ class MainMetaCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("mainMetaData") /** * Gets the main metadata from the database. @@ -49,7 +50,7 @@ class MainMetaCollection : KordExKoinComponent { */ suspend fun update(meta: MainMetaData) = collection.findOneAndReplace( - MainMetaData::id eq "mainMeta", + eq(MainMetaData::id.name, "mainMeta"), meta ) } @@ -67,7 +68,7 @@ class ConfigMetaCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.configDatabase.getCollection() + internal val collection = db.configDatabase.getCollection("configMetaData") /** * Gets the config metadata from the database. @@ -96,7 +97,7 @@ class ConfigMetaCollection : KordExKoinComponent { */ suspend fun update(meta: ConfigMetaData) = collection.findOneAndReplace( - ConfigMetaData::id eq "configMeta", + eq(ConfigMetaData::id.name, "configMeta"), meta ) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt index 2851da56..df41b9d7 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt @@ -1,11 +1,14 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.NewsChannelPublishingData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains functions for interacting with the [news channel publishing database][NewsChannelPublishingData]. @@ -22,7 +25,7 @@ class NewsChannelPublishingCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("newsChannelPublishingData") /** * Adds a channel for auto-publishing. @@ -47,8 +50,10 @@ class NewsChannelPublishingCollection : KordExKoinComponent { */ suspend inline fun removeAutoPublishingChannel(inputGuildId: Snowflake, inputChannelId: Snowflake) = collection.deleteOne( - NewsChannelPublishingData::guildId eq inputGuildId, - NewsChannelPublishingData::channelId eq inputChannelId + and( + eq(NewsChannelPublishingData::guildId.name, inputGuildId), + eq(NewsChannelPublishingData::channelId.name, inputChannelId) + ) ) /** @@ -66,8 +71,8 @@ class NewsChannelPublishingCollection : KordExKoinComponent { inputChannelId: Snowflake ): NewsChannelPublishingData? = collection.findOne( - NewsChannelPublishingData::guildId eq inputGuildId, - NewsChannelPublishingData::channelId eq inputChannelId + eq(NewsChannelPublishingData::guildId.name, inputGuildId), + eq(NewsChannelPublishingData::channelId.name, inputChannelId) ) /** @@ -80,7 +85,7 @@ class NewsChannelPublishingCollection : KordExKoinComponent { * @since 4.7.0 */ suspend inline fun getAutoPublishingChannels(inputGuildId: Snowflake): List = - collection.find(NewsChannelPublishingData::guildId eq inputGuildId).toList() + collection.find(eq(NewsChannelPublishingData::guildId.name, inputGuildId)).toList() /** * Clears all the auto-publishing channels from a guild. @@ -91,6 +96,6 @@ class NewsChannelPublishingCollection : KordExKoinComponent { * @since 4.7.0 */ suspend inline fun clearAutoPublishingForGuild(inputGuildId: Snowflake) { - collection.deleteMany(NewsChannelPublishingData::guildId eq inputGuildId) + collection.deleteMany(eq(NewsChannelPublishingData::guildId.name, inputGuildId)) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt index 90e719d2..d9074f53 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt @@ -1,14 +1,16 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import kotlinx.datetime.DateTimePeriod import kotlinx.datetime.TimeZone import kotlinx.datetime.plus import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.ReminderData import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with []the reminder database][ReminderData]. This @@ -28,7 +30,7 @@ class ReminderCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("reminderData") /** * Gets all the reminders currently in the database. @@ -48,7 +50,7 @@ class ReminderCollection : KordExKoinComponent { * @since 4.2.0 */ suspend fun getRemindersForUser(userId: Snowflake): List = - collection.find(ReminderData::userId eq userId).toList() + collection.find(eq(ReminderData::userId.name, userId)).toList() /** * Gets all the reminders in the database for a specific user, in a specific guild. @@ -80,7 +82,7 @@ class ReminderCollection : KordExKoinComponent { * @since 4.2.0 */ suspend fun removeReminder(userId: Snowflake, number: Long) = - collection.deleteOne(ReminderData::userId eq userId, ReminderData::id eq number) + collection.deleteOne(and(eq(ReminderData::userId.name, userId), eq(ReminderData::id.name, number))) /** * Removes all the reminders for a given guild. @@ -89,7 +91,7 @@ class ReminderCollection : KordExKoinComponent { * @author NoComment1105 * @since 4.2.0 */ - suspend fun removeGuildReminders(guildId: Snowflake) = collection.deleteMany(ReminderData::guildId eq guildId) + suspend fun removeGuildReminders(guildId: Snowflake) = collection.deleteMany(eq(ReminderData::guildId.name, guildId)) /** * Updates a repeating reminder to be extended by the given [repeatingInterval]. diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt index f8319ee5..7ef54e50 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt @@ -1,11 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.RoleMenuData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Role Menu Database][RoleMenuData]. This class contains @@ -21,7 +22,7 @@ class RoleMenuCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("roleMenuData") /** * Using the provided [inputMessageId] the associated [RoleMenuData] will be returned from the database. @@ -32,7 +33,7 @@ class RoleMenuCollection : KordExKoinComponent { * @since 3.4.0 */ suspend inline fun getRoleData(inputMessageId: Snowflake): RoleMenuData? = - collection.findOne(RoleMenuData::messageId eq inputMessageId) + collection.findOne(eq(RoleMenuData::messageId.name, inputMessageId)) /** * Add the given [inputRoles] to the database entry for the role menu for the provided [inputMessageId], @@ -52,7 +53,7 @@ class RoleMenuCollection : KordExKoinComponent { inputRoles: MutableList ) { val newRoleMenu = RoleMenuData(inputMessageId, inputChannelId, inputGuildId, inputRoles) - collection.deleteOne(RoleMenuData::messageId eq inputMessageId) + collection.deleteOne(eq(RoleMenuData::messageId.name, inputMessageId)) collection.insertOne(newRoleMenu) } @@ -65,11 +66,11 @@ class RoleMenuCollection : KordExKoinComponent { * @since 3.4.0 */ suspend inline fun removeRoleFromMenu(inputMessageId: Snowflake, inputRoleId: Snowflake) { - val roleMenu = collection.findOne(RoleMenuData::messageId eq inputMessageId) ?: return + val roleMenu = collection.findOne(eq(RoleMenuData::messageId.name, inputMessageId)) ?: return roleMenu.roles.remove(inputRoleId) - collection.deleteOne(RoleMenuData::messageId eq inputMessageId) + collection.deleteOne(eq(RoleMenuData::messageId.name, inputMessageId)) collection.insertOne(roleMenu) } @@ -81,5 +82,5 @@ class RoleMenuCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun removeAllRoleMenus(inputGuildId: Snowflake) = - collection.deleteMany(RoleMenuData::guildId eq inputGuildId) + collection.deleteMany(eq(RoleMenuData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt index 027e5272..849ebd9b 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq +import com.mongodb.client.model.Updates import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.RoleSubscriptionData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Role Subscription database][RoleSubscriptionData]. This @@ -22,7 +24,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("roleSubscriptionData") /** * Gets the roles that are subscribable for a given guild. @@ -34,7 +36,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun getSubscribableRoles(inputGuildId: Snowflake): RoleSubscriptionData? = - collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) + collection.findOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) /** * Creates a subscribable role record in the database. This should only be used if a record does not already exist. @@ -58,12 +60,12 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun addSubscribableRole(inputGuildId: Snowflake, inputRoleId: Snowflake): Boolean? { - val col = collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) ?: return null + val col = collection.findOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) ?: return null val newRoleList = col.subscribableRoles if (newRoleList.contains(inputRoleId)) return false else newRoleList.add(inputRoleId) collection.updateOne( - RoleSubscriptionData::guildId eq inputGuildId, - RoleSubscriptionData(inputGuildId, newRoleList) + eq(RoleSubscriptionData::guildId.name, inputGuildId), + Updates.set(RoleSubscriptionData::guildId.name, newRoleList) ) return true } @@ -79,7 +81,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun removeSubscribableRole(inputGuildId: Snowflake, inputRoleId: Snowflake): Boolean? { - val col = collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) ?: return null + val col = collection.findOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) ?: return null val newRoleList = col.subscribableRoles if (!newRoleList.contains(inputRoleId)) { return false @@ -88,8 +90,8 @@ class RoleSubscriptionCollection : KordExKoinComponent { if (!removal) return false } collection.updateOne( - RoleSubscriptionData::guildId eq inputGuildId, - RoleSubscriptionData(inputGuildId, newRoleList) + eq(RoleSubscriptionData::guildId.name, inputGuildId), + Updates.set(RoleSubscriptionData::guildId.name, newRoleList) ) return true } @@ -103,5 +105,5 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun removeAllSubscribableRoles(inputGuildId: Snowflake) = - collection.deleteOne(RoleSubscriptionData::guildId eq inputGuildId) + collection.deleteOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt index aaccbba8..f6e265f9 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt @@ -2,7 +2,9 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent import org.hyacinthbots.lilybot.database.Database +import org.hyacinthbots.lilybot.database.deleteOne import org.hyacinthbots.lilybot.database.entities.StatusData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject /** @@ -17,7 +19,7 @@ class StatusCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("statusData") /** * Gets Lily's status from the database. diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt index 89584046..1f5d7e6e 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt @@ -1,11 +1,14 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.TagsData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Tags Database][TagsData]. This class has functions for @@ -22,7 +25,7 @@ class TagsCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("tagsData") /** * Gets the given tag using it's [name] and returns its [TagsData]. If the tag does not exist. @@ -35,7 +38,7 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun getTag(inputGuildId: Snowflake, name: String): TagsData? = - collection.findOne(TagsData::guildId eq inputGuildId, TagsData::name eq name) + collection.findOne(and(eq(TagsData::guildId.name, inputGuildId), eq(TagsData::name.name, name))) /** * Gets all tags in the given [inputGuildId]. @@ -46,7 +49,7 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun getAllTags(inputGuildId: Snowflake): List = - collection.find(TagsData::guildId eq inputGuildId).toList() + collection.find(eq(TagsData::guildId.name, inputGuildId)).toList() /** * Adds a tag to the database, using the provided parameters. @@ -59,12 +62,12 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun setTag( - inputGuildId: Snowflake, - name: String, - tagTitle: String, - tagValue: String, - tagAppearance: String - ) = + inputGuildId: Snowflake, + name: String, + tagTitle: String, + tagValue: String, + tagAppearance: String + ) = collection.insertOne(TagsData(inputGuildId, name, tagTitle, tagValue, tagAppearance)) /** @@ -76,7 +79,7 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun removeTag(inputGuildId: Snowflake, name: String) = - collection.deleteOne(TagsData::guildId eq inputGuildId, TagsData::name eq name) + collection.deleteOne(and(eq(TagsData::guildId.name, inputGuildId), eq(TagsData::name.name, name))) /** * Clears all tags for the provided [inputGuildId]. @@ -86,5 +89,5 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun clearTags(inputGuildId: Snowflake) = - collection.deleteMany(TagsData::guildId eq inputGuildId) + collection.deleteMany(eq(TagsData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt index c65ad4ee..d9acef10 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.ThreadData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class stores all the functions for interacting with the [Threads Database][ThreadData]. This class contains @@ -23,7 +25,7 @@ class ThreadsCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("threadsData") /** * Using the provided [inputThreadId] the thread is returned. @@ -35,7 +37,7 @@ class ThreadsCollection : KordExKoinComponent { * @since 3.2.0 */ suspend inline fun getThread(inputThreadId: Snowflake): ThreadData? = - collection.findOne(ThreadData::threadId eq inputThreadId) + collection.findOne(eq(ThreadData::threadId.name, inputThreadId)) /** * Gets all threads into a list and return them to the user. @@ -56,7 +58,7 @@ class ThreadsCollection : KordExKoinComponent { * @since 3.2.0 */ suspend inline fun getOwnerThreads(inputOwnerId: Snowflake): List = - collection.find(ThreadData::ownerId eq inputOwnerId).toList() + collection.find(eq(ThreadData::ownerId.name, inputOwnerId)).toList() /** * Add or update the ownership of the given [inputThreadId] to the given [newOwnerId]. @@ -78,7 +80,7 @@ class ThreadsCollection : KordExKoinComponent { parentChannelId: Snowflake?, preventArchiving: Boolean = false ) { - collection.deleteOne(ThreadData::threadId eq inputThreadId) + collection.deleteOne(eq(ThreadData::threadId.name, inputThreadId)) collection.insertOne(ThreadData(inputGuildId, inputThreadId, newOwnerId, parentChannelId, preventArchiving)) } @@ -91,7 +93,7 @@ class ThreadsCollection : KordExKoinComponent { * @since 3.2.2 */ suspend inline fun removeThread(inputThreadId: Snowflake) = - collection.deleteOne(ThreadData::threadId eq inputThreadId) + collection.deleteOne(eq(ThreadData::threadId.name, inputThreadId)) /** * This function deletes the ownership data stored in database for the given [inputGuildId]. @@ -102,5 +104,5 @@ class ThreadsCollection : KordExKoinComponent { * @since 4.1.0 */ suspend inline fun removeGuildThreads(inputGuildId: Snowflake) = - collection.deleteMany(ThreadData::guildId eq inputGuildId) + collection.deleteMany(eq(ThreadData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt index f7f4057e..0394f7cb 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt @@ -4,6 +4,7 @@ import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent import kotlinx.datetime.Instant import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.UptimeData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject /** @@ -18,7 +19,7 @@ class UptimeCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("uptimeData") /** * Gets the uptime data from the database. diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt index cb64da4d..5c16e6d9 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.WarnData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class stores all the functions for interacting with the [Warn Database][WarnData]. The class contains the @@ -20,7 +22,7 @@ class WarnCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("warnData") /** * Gets the number of points the provided [inputUserId] has in the provided [inputGuildId] from the database. @@ -33,8 +35,10 @@ class WarnCollection : KordExKoinComponent { */ suspend inline fun getWarn(inputUserId: Snowflake, inputGuildId: Snowflake): WarnData? = collection.findOne( - WarnData::userId eq inputUserId, - WarnData::guildId eq inputGuildId + and( + eq(WarnData::userId.name, inputUserId), + eq(WarnData::guildId.name, inputGuildId) + ) ) /** @@ -48,7 +52,7 @@ class WarnCollection : KordExKoinComponent { */ suspend inline fun setWarn(inputUserId: Snowflake, inputGuildId: Snowflake, remove: Boolean) { val currentStrikes = getWarn(inputUserId, inputGuildId)?.strikes ?: 0 - collection.deleteOne(WarnData::userId eq inputUserId, WarnData::guildId eq inputGuildId) + collection.deleteOne(and(eq(WarnData::userId.name, inputUserId), eq(WarnData::guildId.name, inputGuildId))) collection.insertOne( WarnData( inputUserId, @@ -66,5 +70,5 @@ class WarnCollection : KordExKoinComponent { * @since 3.0.0 */ suspend inline fun clearWarns(inputGuildId: Snowflake) = - collection.deleteMany(WarnData::guildId eq inputGuildId) + collection.deleteMany(eq(WarnData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt index adc9e613..b1930220 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt @@ -8,12 +8,15 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import dev.kord.core.Kord +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.WelcomeChannelData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq import org.quiltmc.community.cozy.modules.welcome.data.WelcomeChannelData as CozyWelcomeChannelData /** @@ -30,25 +33,25 @@ class WelcomeChannelCollection : KordExKoinComponent, CozyWelcomeChannelData { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection("welcomeChannelData") override suspend fun getChannelURLs(): Map = collection.find() .toList().associate { it.channelId to it.url } override suspend fun getUrlForChannel(channelId: Snowflake): String? = - collection.findOne(WelcomeChannelData::channelId eq channelId) + collection.findOne(eq(WelcomeChannelData::channelId.name, channelId)) ?.url override suspend fun setUrlForChannel(channelId: Snowflake, url: String) { - collection.save(WelcomeChannelData(channelId, url)) + collection.replaceOne(Filters.empty(), WelcomeChannelData(channelId, url)) } override suspend fun removeChannel(channelId: Snowflake): String? { val url = getUrlForChannel(channelId) ?: return null - collection.deleteOne(WelcomeChannelData::channelId eq channelId) + collection.deleteOne(eq(WelcomeChannelData::channelId.name, channelId)) return url } @@ -56,7 +59,7 @@ class WelcomeChannelCollection : KordExKoinComponent, CozyWelcomeChannelData { suspend fun removeWelcomeChannelsForGuild(guildId: Snowflake, kord: Kord) { val guild = kord.getGuildOrNull(guildId) ?: return guild.channels.collect { - collection.deleteOne(WelcomeChannelData::channelId eq it.id) + collection.deleteOne(eq(WelcomeChannelData::channelId.name, it.id)) } } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt index d63e0460..824c26fe 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt @@ -1,20 +1,20 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.LoggingConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV1(configDb: CoroutineDatabase) { +suspend fun configV1(configDb: MongoDatabase) { with(configDb.getCollection("loggingConfigData")) { updateMany( - LoggingConfigData::enableMessageEditLogs exists false, - setValue(LoggingConfigData::enableMessageEditLogs, false) + Filters.exists(LoggingConfigData::enableMessageEditLogs.name, false), + Updates.set(LoggingConfigData::enableMessageEditLogs.name, false) ) } configDb.getCollection("loggingConfigData").updateMany( - "{}", - "{\$rename: {enableMessageLogs: \"enableMessageDeleteLogs\"}}" + Filters.empty(), + Updates.rename("enableMessageLogs", "enableMessageDeleteLogs") ) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt index fa6afca6..1c11e2e3 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt @@ -1,20 +1,20 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ModerationConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV2(db: CoroutineDatabase) { +suspend fun configV2(db: MongoDatabase) { with(db.getCollection("moderationConfigData")) { updateMany( - ModerationConfigData::quickTimeoutLength exists false, - setValue(ModerationConfigData::quickTimeoutLength, null) + Filters.exists(ModerationConfigData::quickTimeoutLength.name, false), + Updates.set(ModerationConfigData::quickTimeoutLength.name, null) ) updateMany( - ModerationConfigData::autoPunishOnWarn exists false, - setValue(ModerationConfigData::autoPunishOnWarn, null) + Filters.exists(ModerationConfigData::autoPunishOnWarn.name, false), + Updates.set(ModerationConfigData::autoPunishOnWarn.name, null) ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt index 857d8022..011aac7a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt @@ -1,23 +1,23 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.LoggingConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV3(db: CoroutineDatabase) { +suspend fun configV3(db: MongoDatabase) { with(db.getCollection("loggingConfigData")) { updateMany( - LoggingConfigData::enablePublicMemberLogs exists false, - setValue(LoggingConfigData::enablePublicMemberLogs, false) + Filters.exists(LoggingConfigData::enablePublicMemberLogs.name, false), + Updates.set(LoggingConfigData::enablePublicMemberLogs.name, false) ) updateMany( - LoggingConfigData::publicMemberLog exists false, - setValue(LoggingConfigData::publicMemberLog, null) + Filters.exists(LoggingConfigData::publicMemberLog.name, false), + Updates.set(LoggingConfigData::publicMemberLog.name, null) ) updateMany( - LoggingConfigData::publicMemberLogData exists false, - setValue(LoggingConfigData::publicMemberLogData, null) + Filters.exists(LoggingConfigData::publicMemberLogData.name, false), + Updates.set(LoggingConfigData::publicMemberLogData.name, null) ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt index 3c214b91..99ef32ce 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt @@ -1,9 +1,9 @@ package org.hyacinthbots.lilybot.database.migrations.config -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase @Suppress("UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier") -suspend fun configV4(db: CoroutineDatabase) { +suspend fun configV4(db: MongoDatabase) { // Support config has been removed. // if (db.getCollection().find().toList().isEmpty()) { // db.dropCollection("supportConfigData") diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt index 1a264ed1..edd5e203 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt @@ -2,9 +2,9 @@ package org.hyacinthbots.lilybot.database.migrations.config -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun configV5(db: CoroutineDatabase) { +suspend fun configV5(db: MongoDatabase) { // val collection = db.getCollection("utilityConfigData") // val oldConfigs = collection.find().toList() // val newConfigs = mutableListOf() diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt index da9c7cd0..f69f1606 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt @@ -1,15 +1,15 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ModerationConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV6(db: CoroutineDatabase) { +suspend fun configV6(db: MongoDatabase) { with(db.getCollection("moderationConfigData")) { updateMany( - ModerationConfigData::banDmMessage exists false, - setValue(ModerationConfigData::banDmMessage, null) + Filters.exists(ModerationConfigData::banDmMessage.name, false), + Updates.set(ModerationConfigData::banDmMessage.name, null) ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt index cbeb8940..2b3f856a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt @@ -1,10 +1,10 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.StatusData -import org.litote.kmongo.coroutine.CoroutineDatabase // This was commented out due to the remindme data class being removed -suspend fun mainV1(db: CoroutineDatabase) { +suspend fun mainV1(db: MongoDatabase) { // val reminders = db.getCollection("remindMeData") // // val repeating = mutableListOf>() @@ -63,7 +63,7 @@ suspend fun mainV1(db: CoroutineDatabase) { // reminders.bulkWrite(requests = nonRepeating, BulkWriteOptions().ordered(true)) // } - db.dropCollection("statusData") + db.getCollection("statusData").drop() db.createCollection("statusData") db.getCollection("statusData").insertOne(StatusData(null)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt index cb8682fc..ea8405b1 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt @@ -1,12 +1,12 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ThreadData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun mainV2(db: CoroutineDatabase) { - with(db.getCollection()) { - updateMany(ThreadData::guildId exists false, setValue(ThreadData::guildId, null)) +suspend fun mainV2(db: MongoDatabase) { + with(db.getCollection("threadData")) { + updateMany(Filters.exists(ThreadData::guildId.name, false), Updates.set(ThreadData::guildId.name, null)) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt index 3b775ed7..7fc4896e 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt @@ -1,8 +1,8 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun mainV3(db: CoroutineDatabase) { - db.dropCollection("remindMeData") +suspend fun mainV3(db: MongoDatabase) { + // db.getCollection("remindMeData") db.createCollection("reminderData") } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt index 4c5dc577..30bedd90 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt @@ -1,8 +1,8 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun mainV4(db: CoroutineDatabase) { +suspend fun mainV4(db: MongoDatabase) { db.createCollection("welcomeChannelData") db.createCollection("githubData") } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt index 9d1f5d87..0c2b9e01 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt @@ -1,15 +1,18 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ThreadData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun mainV5(db: CoroutineDatabase) { +suspend fun mainV5(db: MongoDatabase) { // db.createCollection("autoThreadingData") - with(db.getCollection()) { - updateMany(ThreadData::parentChannelId exists false, setValue(ThreadData::parentChannelId, null)) + with(db.getCollection("threadData")) { + updateMany( + Filters.exists(ThreadData::parentChannelId.name, false), + Updates.set(ThreadData::parentChannelId.name, null) + ) } // with(configDb.getCollection()) { diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt index ac8b0e21..04ea448a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt @@ -1,12 +1,15 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.AutoThreadingData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun mainV6(db: CoroutineDatabase) { - with(db.getCollection()) { - updateMany(AutoThreadingData::addModsAndRole exists false, setValue(AutoThreadingData::addModsAndRole, false)) +suspend fun mainV6(db: MongoDatabase) { + with(db.getCollection("autoThreadingData")) { + updateMany( + Filters.exists(AutoThreadingData::addModsAndRole.name, false), + Updates.set(AutoThreadingData::addModsAndRole.name, false) + ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt index 6c14d1de..962c8ca6 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt @@ -1,7 +1,7 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun mainV7(db: CoroutineDatabase) { +suspend fun mainV7(db: MongoDatabase) { db.createCollection("newsChannelPublishingData") } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt index 0995230d..5bea5345 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt @@ -1,7 +1,7 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun mainV8(db: CoroutineDatabase) { +suspend fun mainV8(db: MongoDatabase) { db.createCollection("roleSubscriptionData") } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt index 0ac485e1..d2e99172 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt @@ -1,7 +1,8 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun mainV9(db: CoroutineDatabase) { - db.dropCollection("logUploadingBlacklistData") +@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier") +suspend fun mainV9(db: MongoDatabase) { + // db.getCollection<>("logUploadingBlacklistData") } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt index 6790aa07..cd68c37c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt @@ -10,7 +10,11 @@ import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent import com.kotlindiscord.kord.extensions.storage.Data import com.kotlindiscord.kord.extensions.storage.DataAdapter import com.kotlindiscord.kord.extensions.storage.StorageUnit +import com.mongodb.client.model.Filters import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq +import com.mongodb.kotlin.client.coroutine.MongoCollection +import kotlinx.coroutines.flow.firstOrNull import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.serializer @@ -18,13 +22,11 @@ import org.bson.conversions.Bson import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.AdaptedData import org.koin.core.component.inject -import org.litote.kmongo.coroutine.CoroutineCollection -import org.litote.kmongo.eq @OptIn(InternalSerializationApi::class) class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { private val database: Database by inject() - private val collectionCache: MutableMap> = mutableMapOf() + private val collectionCache: MutableMap> = mutableMapOf() private fun StorageUnit<*>.getIdentifier(): String = buildString { @@ -38,7 +40,7 @@ class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { append(identifier) } - private fun getCollection(namespace: String): CoroutineCollection { + private fun getCollection(namespace: String): MongoCollection { var collection = collectionCache[namespace] if (collection == null) { @@ -51,14 +53,14 @@ class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { } private fun constructQuery(unit: StorageUnit<*>): Bson { - var query = AdaptedData::identifier eq unit.identifier + var query = eq(AdaptedData::identifier.name, unit.identifier) - query = and(query, AdaptedData::type eq unit.storageType) + query = and(query, eq(AdaptedData::type.name, unit.storageType)) - query = and(query, AdaptedData::channel eq unit.channel) - query = and(query, AdaptedData::guild eq unit.guild) - query = and(query, AdaptedData::message eq unit.message) - query = and(query, AdaptedData::user eq unit.user) + query = and(query, eq(AdaptedData::channel.name, unit.channel)) + query = and(query, eq(AdaptedData::guild.name, unit.guild)) + query = and(query, eq(AdaptedData::message.name, unit.message)) + query = and(query, eq(AdaptedData::user.name, unit.user)) return query } @@ -88,8 +90,7 @@ class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { override suspend fun reload(unit: StorageUnit): R? { val dataId = unit.getIdentifier() - val result = getCollection(unit.namespace) - .findOne(constructQuery(unit))?.data + val result = getCollection(unit.namespace).find(constructQuery(unit)).firstOrNull()?.data if (result != null) { dataCache[dataId] = Json.decodeFromString(unit.dataType.serializer(), result) @@ -102,7 +103,8 @@ class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { override suspend fun save(unit: StorageUnit): R? { val data = get(unit) ?: return null - getCollection(unit.namespace).save( + getCollection(unit.namespace).replaceOne( + Filters.empty(), AdaptedData( identifier = unit.identifier, @@ -126,7 +128,8 @@ class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { dataCache[dataId] = data unitCache[unit] = dataId - getCollection(unit.namespace).save( + getCollection(unit.namespace).replaceOne( + Filters.empty(), AdaptedData( identifier = unit.identifier,