All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.cedrickring.reactormongodb.collection.mono.CountMono.kt Maven / Gradle / Ivy

The newest version!
package com.github.cedrickring.reactormongodb.collection.mono

import com.github.cedrickring.reactormongodb.collection.ReactiveCollection
import com.mongodb.client.model.CountOptions
import org.bson.Document
import org.bson.conversions.Bson
import reactor.core.CoreSubscriber
import reactor.core.publisher.Mono

class CountMono(private val reactiveCollection: ReactiveCollection,
                   private val filter: Bson?,
                   private val countOptions: CountOptions?) : Mono() {

    override fun subscribe(actual: CoreSubscriber?) {
        reactiveCollection.nativeCollection.count(filter ?: Document(), countOptions
                ?: CountOptions()) { count, throwable ->
            if (throwable != null) {
                actual?.onError(throwable)
            } else {
                actual?.onNext(count)
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy