BsonDocument

A BSON document.

To create instances of this class, see BsonFactory.

Navigating BSON types

This interface is part of the BSON trinity:

Usage

val bson: BsonDocument = …

for ((name, field) in bson) {
println("Field: $name • ${field.type}")
}

The iteration order of a BSON document is preserved: fields appear in the same order as they are written in.

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 BsonDocument.Companion.equals and BsonDocument.Companion.hashCode are provided as default implementations.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface Field

A pair of a name and a value.

Properties

Link copied to clipboard
abstract val factory: BsonFactory

The instance of BsonFactory that created this instance.

Link copied to clipboard
abstract val fields: Set<String>

Returns the set of fields in this document.

Link copied to clipboard
abstract val size: Int

The number of fields in this document.

Functions

Link copied to clipboard

Creates an Iterable that wraps this document.

Link copied to clipboard
abstract fun asMap(): Map<String, BsonValue>

Creates a Map view of this document.

Link copied to clipboard

Creates a Sequence of the fields in this document.

Link copied to clipboard
abstract fun asValue(): BsonValue

Returns the BsonValue equivalent to this document.

Link copied to clipboard
infix inline fun <T> BsonDocument.at(path: BsonPath): T

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

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

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

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

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

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

Analyzes the difference between two BSON documents.

Link copied to clipboard
abstract operator fun get(field: String): BsonValue?

Returns the element with named field.

Link copied to clipboard
open fun isEmpty(): Boolean

Returns true if this document has no fields.

Link copied to clipboard
open fun isNotEmpty(): Boolean

Returns true if this document has at least one field.

Link copied to clipboard
abstract operator fun iterator(): Iterator<BsonDocument.Field>

Iterates over the fields in this document.

Link copied to clipboard
inline fun <T> BsonDocument.select(@Language(value = "JSONPath") path: String): Sequence<T>
inline fun <T> BsonDocument.select(path: BsonPath): Sequence<T>

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

Link copied to clipboard
inline fun <T> BsonDocument.selectFirst(@Language(value = "JSONPath") path: String): T
inline fun <T> BsonDocument.selectFirst(path: BsonPath): T

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

Link copied to clipboard
abstract fun toByteArray(): ByteArray

Generates a ByteArray of the raw BSON representation of this value.

Link copied to clipboard
abstract override fun toString(): String

JSON representation of this BsonDocument object, as a String.