BsonFactory

Creates KtMongo BsonDocument and BsonArray instances by wrapping the equivalents from the official drivers.

actual class BsonFactory(codecRegistry: CodecRegistry) : BsonFactory(source)

BsonDocument and BsonArray factory that uses the official MongoDB driver's CodecRegistry machinery.

Documents and arrays created from this class follow your existing configuration of the official MongoDB driver, including any library supported by the official MongoDB driver (KotlinX.Serialization, Jackson…).

This factory also adds support for the types specific to KtMongo. If you also use the official driver directly, you will need to configure it to access the KtMongo codecs. To learn more, see BsonFactory.codecRegistry.

Constructors

Link copied to clipboard
constructor(codecRegistry: CodecRegistry)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val codecRegistry: CodecRegistry

The CodecRegistry used by this factory to create and read documents.

Functions

Link copied to clipboard
expect open override fun buildArray(block: BsonValueWriter.() -> Unit): BsonArray
expect open override fun buildArray(instance: BsonValueWriteable): BsonArray
actual open override fun buildArray(block: BsonValueWriter.() -> Unit): BsonArray
actual open override fun buildArray(instance: BsonValueWriteable): BsonArray
Link copied to clipboard
expect open override fun buildDocument(block: BsonFieldWriter.() -> Unit): BsonDocument
expect open override fun buildDocument(instance: BsonFieldWriteable): BsonDocument
actual open override fun buildDocument(block: BsonFieldWriter.() -> Unit): BsonDocument
actual open override fun buildDocument(instance: BsonFieldWriteable): BsonDocument
Link copied to clipboard
expect open override fun <T : Any> encode(obj: T, type: KType): BsonDocument
actual open override fun <T : Any> encode(obj: T, type: KType): BsonDocument
Link copied to clipboard
inline fun <T : Any> BsonFactory.encode(obj: T): BsonDocument

Writes an arbitrary Kotlin obj into a top-level BSON document.

Link copied to clipboard
inline fun <T> findCodecForType(): Codec<T>

Returns the instance of Codec (from the official MongoDB driver) that is used to encode or decode the given type T.

fun <T> findCodecForType(type: KType): Codec<T>

Returns the instance of Codec (from the official MongoDB driver) that is used to encode or decode the given type.

Link copied to clipboard
expect open override fun readArray(bytes: ByteArray): BsonArray
expect open override fun readArray(array: BsonArray): BsonArray
actual open override fun readArray(bytes: ByteArray): BsonArray
actual open override fun readArray(array: BsonArray): BsonArray

fun readArray(raw: BsonArray): BsonArray

Wraps a org.bson.BsonArray from the official MongoDB driver into its KtMongo equivalent.

Link copied to clipboard
expect open override fun readDocument(bytes: ByteArray): BsonDocument
expect open override fun readDocument(document: BsonDocument): BsonDocument
actual open override fun readDocument(bytes: ByteArray): BsonDocument
actual open override fun readDocument(document: BsonDocument): BsonDocument

fun readDocument(official: BsonDocument): BsonDocument

Wraps a org.bson.BsonDocument from the official MongoDB driver into its KtMongo equivalent.

Link copied to clipboard
expect open override fun readValue(value: BsonValue): BsonValue
actual open override fun readValue(value: BsonValue): BsonValue

fun readValue(raw: BsonValue): BsonValue

Wraps a org.bson.BsonValue from the official MongoDB driver into its KtMongo equivalent.