Skip to content

BsonDocument

Pure Kotlin implementation of opensavvy.ktmongo.bson.BsonDocument.

To create instances of this class, see BsonFactory.

This page describes the BSON multiplatform implementation. To learn more about the general BSON operations, see opensavvy.ktmongo.bson.BsonDocument.

This class 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.

Thread-safety

This class is not thread-safe. Although it is not possible to mutate its state, this class uses internal mutation to lazily decode the BSON stream.

Types

Field

class Field(val name: String, val value: BsonValue) : BsonDocument.Field

Serializer

Serializer for the multiplatform opensavvy.ktmongo.bson.multiplatform.BsonDocument implementation.

Properties

factory

open override val factory: BsonFactory

fields

open override val fields: Set<String>

size

open override val size: Int

Functions

asIterable

open override fun asIterable(): Iterable<BsonDocument.Field>

asMap

open override fun asMap(): Map<String, BsonValue>

asSequence

open override fun asSequence(): Sequence<BsonDocument.Field>

asValue

open override fun asValue(): BsonValue

decode

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

equals

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

get

open operator override fun get(field: String): BsonValue?

hashCode

open override fun hashCode(): Int

isEmpty

open override fun isEmpty(): Boolean

isNotEmpty

open fun isNotEmpty(): Boolean

iterator

open operator override fun iterator(): Iterator<BsonDocument.Field>

toByteArray

open override fun toByteArray(): ByteArray

toString

open override fun toString(): String