Skip to content

BsonValue

Implementation of opensavvy.ktmongo.bson.BsonValue based on the official MongoDB drivers.

The BSON specification only allows root [`documents`](../../../bson/opensavvy.ktmongo.bson/-bson-document/index.md), so it is not possible to instantiate this interface directly with a complex structure. This interface is used to decode the fields of a [`BsonDocument`](../../../bson/opensavvy.ktmongo.bson/-bson-document/index.md) or the items of a [`BsonArray`](../../../bson/opensavvy.ktmongo.bson/-bson-array/index.md).

To instantiate a [`BsonDocument`](../../../bson/opensavvy.ktmongo.bson/-bson-document/index.md) or [`BsonArray`](../../../bson/opensavvy.ktmongo.bson/-bson-array/index.md), see [`BsonFactory`](../../../bson/opensavvy.ktmongo.bson/-bson-factory/index.md).

<blockquote markdown>

This page describes the BSON implementation based on the official MongoDB drivers. To learn more about the general BSON operations, see [`opensavvy.ktmongo.bson.BsonArray`](../../../bson/opensavvy.ktmongo.bson/-bson-array/index.md).


</blockquote>
### Navigating BSON types
This interface is part of the BSON trinity:

 - [`BsonDocument`](../-bson-document/index.md) represents an entire BSON document.


 - [`BsonArray`](../-bson-array/index.md) represents an array of BSON values.


 - [`BsonValue`](index.md) represents a single value in isolation.


### Usage
If this BSON value is the serialized form of a Kotlin DTO, see [`decode`](index.md#decode).

This interface provides methods for decoding the different BSON native types, like [`decodeInt32`](index.md#decodeint32), [`decodeObjectId`](index.md#decodeobjectid) and [`decodeInstant`](index.md#decodeinstant).

Some BSON types cannot be represented by a single Kotlin type, so multiple methods are provided to decode their components. For example: [`decodeRegularExpressionPattern`](index.md#decoderegularexpressionpattern) and [`decodeRegularExpressionOptions`](index.md#decoderegularexpressionoptions).

Implementation of a KtMongo opensavvy.ktmongo.bson.BsonValue that wraps a org.bson.BsonValue.

To create an instance of this class, see BsonFactory.readValue.

Types

Serializer

expect object Serializer : KSerializer<BsonValue> 

actual object Serializer : KSerializer<BsonValue> 

Serializer for the official opensavvy.ktmongo.bson.official.BsonValue implementation.

Properties

factory

expect open override val factory: BsonFactory

actual open override val factory: BsonFactory

raw

val raw: BsonValue

type

abstract val type: BsonType
open override val type: BsonType

Functions

decode

@LowLevelApi
abstract fun <T> decode(type: KType): T
@LowLevelApi
open override fun <T> decode(type: KType): T

decodeArray

expect open override fun decodeArray(): BsonArray

actual open override fun decodeArray(): BsonArray

decodeBinaryData

abstract fun decodeBinaryData(): ByteArray
open override fun decodeBinaryData(): ByteArray

decodeBinaryDataType

abstract fun decodeBinaryDataType(): UByte
open override fun decodeBinaryDataType(): UByte

decodeBoolean

abstract fun decodeBoolean(): Boolean
open override fun decodeBoolean(): Boolean

decodeDateTime

abstract fun decodeDateTime(): Long
open override fun decodeDateTime(): Long

decodeDBPointerId

abstract fun decodeDBPointerId(): ObjectId
open override fun decodeDBPointerId(): ObjectId

decodeDBPointerNamespace

open override fun decodeDBPointerNamespace(): String

decodeDecimal128Bytes

decodeDocument

expect open override fun decodeDocument(): BsonDocument

actual open override fun decodeDocument(): BsonDocument

decodeDouble

abstract fun decodeDouble(): Double
open override fun decodeDouble(): Double

decodeInstant

open fun decodeInstant(): Instant
open fun decodeInstant(): Instant

decodeInt32

abstract fun decodeInt32(): Int
open override fun decodeInt32(): Int

decodeInt64

abstract fun decodeInt64(): Long
open override fun decodeInt64(): Long

decodeJavaScript

abstract fun decodeJavaScript(): String
open override fun decodeJavaScript(): String

decodeJavaScriptScope

open override fun decodeJavaScriptScope(): BsonDocument

decodeMaxKey

abstract fun decodeMaxKey()
open override fun decodeMaxKey()

decodeMinKey

abstract fun decodeMinKey()
open override fun decodeMinKey()

decodeNull

abstract fun decodeNull(): Nothing?
open override fun decodeNull(): Nothing?

decodeObjectId

open fun decodeObjectId(): ObjectId
open fun decodeObjectId(): ObjectId

decodeObjectIdBytes

@LowLevelApi
open override fun decodeObjectIdBytes(): ByteArray

decodeRegularExpressionOptions

open override fun decodeRegularExpressionOptions(): String

decodeRegularExpressionPattern

open override fun decodeRegularExpressionPattern(): String

decodeString

abstract fun decodeString(): String
open override fun decodeString(): String

decodeSymbol

abstract fun decodeSymbol(): String
open override fun decodeSymbol(): String

decodeTimestamp

abstract fun decodeTimestamp(): Timestamp
open override fun decodeTimestamp(): Timestamp

decodeUndefined

abstract fun decodeUndefined()
open override fun decodeUndefined()

decodeVector

open fun decodeVector(): Vector
open fun decodeVector(): Vector

equals

open operator override fun equals(other: Any?): Boolean

hashCode

open override fun hashCode(): Int

takeIfPresent

open fun takeIfPresent(): BsonValue?
open fun takeIfPresent(): BsonValue?

toString

open override fun toString(): String