com.github.cedrickring.reactormongodb.collection.mono.DeleteMono.kt Maven / Gradle / Ivy
package com.github.cedrickring.reactormongodb.collection.mono
import com.github.cedrickring.reactormongodb.collection.ReactiveCollection
import com.mongodb.client.model.DeleteOptions
import com.mongodb.client.result.DeleteResult
import org.bson.conversions.Bson
import reactor.core.CoreSubscriber
import reactor.core.publisher.Mono
class DeleteMono(private val reactiveCollection: ReactiveCollection,
private val filter: Bson,
private val deleteOptions: DeleteOptions,
private val many: Boolean = false) : Mono() {
override fun subscribe(actual: CoreSubscriber?) {
val callback: (deleteResult: DeleteResult, throwable: Throwable?) -> Unit = { deleteResult, throwable ->
if (throwable == null) {
actual?.onNext(deleteResult)
} else {
actual?.onError(throwable)
}
}
if (many) {
reactiveCollection.nativeCollection.deleteMany(filter, deleteOptions, callback)
} else {
reactiveCollection.nativeCollection.deleteOne(filter, deleteOptions, callback)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy