BsonValue

An arbitrary BSON value.

The BSON specification only allows root documents, 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 or the items of a BsonArray.

To instantiate a BsonDocument or BsonArray, see BsonFactory.

Navigating BSON types

This interface is part of the BSON trinity:

Usage

If this BSON value is the serialized form of a Kotlin DTO, see decode.

This interface provides methods for decoding the different BSON native types, like decodeInt32, decodeObjectId and decodeInstant.

Some BSON types cannot be represented by a single Kotlin type, so multiple methods are provided to decode their components. For example: decodeRegularExpressionPattern and decodeRegularExpressionOptions.

Equality

Different implementations of this interface are considered equal if they represent the same value with the same type. That is, both values would result in the exact same BSON sent over the wire.

The methods BsonValue.Companion.equals and BsonValue.Companion.hashCode are provided as default implementations.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val factory: BsonFactory

The instance of BsonFactory that created this instance.

Link copied to clipboard
abstract val type: BsonType

The native BSON type of this value.

Functions

Link copied to clipboard
abstract fun <T> decode(type: KType): T

Decodes this value into an instance of the Kotlin type T.

Link copied to clipboard
inline fun <T> BsonValue.decode(): T

Decodes this value into an instance of the Kotlin type T.

Link copied to clipboard
abstract fun decodeArray(): BsonArray

Decodes this value as a nested BsonArray.

Link copied to clipboard
abstract fun decodeBinaryData(): ByteArray

Decodes a binary blob.

Link copied to clipboard
abstract fun decodeBinaryDataType(): UByte

Decodes the type of a binary blob.

Link copied to clipboard
abstract fun decodeBoolean(): Boolean

Decodes this value as a Boolean.

Link copied to clipboard
abstract fun decodeDateTime(): Long

Decodes this value as a UTC timestamp in milliseconds since the Unix epoch.

Link copied to clipboard
abstract fun decodeDBPointerId(): ObjectId

Decodes this value as the ID of a database pointer.

Link copied to clipboard

Decodes this value as the namespace of a database pointer.

Link copied to clipboard

Decodes this value as the bytes of a Decimal128.

Link copied to clipboard

Decodes this value as a nested BsonDocument.

Link copied to clipboard
abstract fun decodeDouble(): Double

Decodes this value as Double.

Link copied to clipboard

Decodes this value as a Kotlin Instant.

Link copied to clipboard
abstract fun decodeInt32(): Int

Decodes this value as Int.

Link copied to clipboard
abstract fun decodeInt64(): Long

Decodes this value as Long.

Link copied to clipboard
abstract fun decodeJavaScript(): String

Decodes this value as JavaScript code.

Link copied to clipboard

Decodes this value as a document describing variables some JavaScript code has access to.

Link copied to clipboard
abstract fun decodeMaxKey()

Decodes the special BSON value BsonType.MaxKey.

Link copied to clipboard
abstract fun decodeMinKey()

Decodes the special BSON value BsonType.MinKey.

Link copied to clipboard
abstract fun decodeNull(): Nothing?

Decodes this value as a Kotlin null.

Link copied to clipboard

Decodes this value as a ObjectId.

Link copied to clipboard

Decodes this value as the bytes of an ObjectId.

Link copied to clipboard

Decodes this value as the options of a regular expression.

Link copied to clipboard

Decodes this value as the pattern of a regular expression.

Link copied to clipboard
abstract fun decodeString(): String

Decodes this value as a string.

Link copied to clipboard
abstract fun decodeSymbol(): String

Decodes this value as a symbol.

Link copied to clipboard
abstract fun decodeTimestamp(): Timestamp

Decodes this value as a Timestamp.

Link copied to clipboard
abstract fun decodeUndefined()

Decodes this value as an undefined value.

Link copied to clipboard
open fun decodeVector(): Vector

Decodes a binary Vector.

Link copied to clipboard
infix fun BsonValue.diff(other: BsonValue): String?

Analyzes the difference between two BSON values.

Link copied to clipboard

Returns this value, unless it is undefined or null, in which case returns null.