Skip to content

Kotlin BSON • Multiplatform abstraction for different BSON implementationsopensavvy.ktmongo.bson

Package-level declarations

Utilities and primitives to read and write BSON documents.

Bson and BsonArray respectively represent BSON documents and arrays.

BsonFactory is the entry point to create new BSON documents.

BsonPath provides a convenient way to search for data in a complex BSON document.

Types

AnyBsonWriter

@LowLevelApi
sealed interface AnyBsonWriter

Parent interface for type parameters that can accept either BsonValueWriter or BsonFieldWriter.

Bson

interface Bson

A BSON document.

BsonArray

interface BsonArray

A BSON array.

BsonArrayReader

@LowLevelApi
interface BsonArrayReader

Utilities for decomposing a BsonArray into its elements.

BsonDocumentReader

@LowLevelApi
interface BsonDocumentReader

Utilities for decomposing a Bson document into its fields.

BsonFactory

interface BsonFactory

Entrypoint for creating Bson and BsonArray instances.

BsonFieldWriteable

interface BsonFieldWriteable

An object that can be represented as fields in a BSON document.

BsonFieldWriter

@LowLevelApi
interface BsonFieldWriter : AnyBsonWriter

Generator of BSON document fields.

BsonPath

sealed interface BsonPath

Access specific fields in arbitrary BSON documents using a JSONPath-like API.

BsonReaderException

class BsonReaderException(message: String, cause: Throwable? = null) : IllegalStateException

Exception thrown when BSON reading fails.

BsonType

The different data types supported in BSON documents.

BsonValueReader

@LowLevelApi
interface BsonValueReader

Representation of a BSON value.

BsonValueWriteable

interface BsonValueWriteable

An object that can be represented as a BSON value (value of a field, item in an array, an array itself).

BsonValueWriter

@LowLevelApi
interface BsonValueWriter : AnyBsonWriter

Generator of BSON values.

BsonWriterDsl

@DslMarker
annotation class BsonWriterDsl

Annotation to mark types that are part of the BSON writer DSL.

ExperimentalBsonDiffApi

annotation class ExperimentalBsonDiffApi

ExperimentalBsonPathApi

annotation class ExperimentalBsonPathApi

Properties

DEPRECATED_IN_BSON_SPEC

Deprecation messages for BSON functionality that is deprecated in the BSON spec.

Functions

at

infix inline fun <T> Bson.at(path: BsonPath): T

Finds the first value that matches path in a given BSON document.

BsonPath

fun BsonPath(@Language
(value = "JSONPath") text: String): BsonPath

Parses an RFC-9535 compliant string expression into a BsonPath instance.

diff

infix fun Bson.diff(other: Bson): String?

Analyzes the difference between two BSON documents.

infix fun BsonArray.diff(other: BsonArray): String?

Analyzes the difference between two BSON arrays.

@LowLevelApi
infix fun BsonArrayReader.diff(other: BsonArrayReader): String?

Analyzes the difference between two BSON arrays.

@LowLevelApi
infix fun BsonDocumentReader.diff(other: BsonDocumentReader): String?

Analyzes the difference between two BSON documents.

@LowLevelApi
infix fun BsonValueReader.diff(other: BsonValueReader): String?

Analyzes the difference between two BSON values.

read

inline fun <T : Any> Bson.read(): T?

Reads this document into an instance of type T.

select

inline fun <T> Bson.select(@Language
(value = "JSONPath") path: String): Sequence<T>

Finds all values that match path in a given BSON document.

inline fun <T> Bson.select(path: BsonPath): Sequence<T>

Finds all values that match path in a given BSON document.

selectFirst

inline fun <T> Bson.selectFirst(@Language
(value = "JSONPath") path: String): T

Finds the first value that matches path in a given BSON document.

inline fun <T> Bson.selectFirst(path: BsonPath): T

Finds the first value that matches path in a given BSON document.

write

inline fun <T : Any> BsonFactory.write(obj: T): Bson

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