Skip to content

CompoundBsonNode

A compound expression is an BsonNode that may have children.

A compound expression may have 0..n children. Children are added by calling the accept function.

This is also the supertype for all DSL scopes, since DSL scopes correspond to the ability to add children to an expression.

Implementation notes

Prefer implementing AbstractCompoundBsonNode instead of implementing this interface directly.

Inheritors

Types

Companion

object Companion

Properties

context

@LowLevelApi



abstract val context: BsonContext

The context used to generate this expression.

Functions

accept

@LowLevelApi



@DangerousMongoApi



abstract override fun accept(node: BsonNode)

Adds a new node as a child of this one.

Since BsonNode subtypes may generate arbitrary BSON, it is possible to use this method to inject arbitrary BSON (escaped or not) into any KtMongo DSL. Incorrect BsonNode implementations can create memory leaks, performance issues, data corruption or data leaks.

We recommend against calling this function directly. Instead, you should find other functions declared on this object (possibly as extensions) that perform the operation you want in safe manner.

acceptAll

@LowLevelApi



@DangerousMongoApi



fun <N : Node> CompoundNode<N>.acceptAll(nodes: Iterable<N>)

Adds any number of nodes into this one.

To learn more about the behavior of this function and the security implications, see accept.

freeze

@LowLevelApi



abstract override fun freeze()

Makes this expression immutable.

After this method has been called, the expression can never be modified again. This ensures that expressions cannot change after they have been used within other expressions.

simplify

@LowLevelApi



abstract fun simplify(): BsonNode?

Returns a simplified (but equivalent) expression to the current expression.

Returns null when the current expression was simplified into a no-op (= it does nothing).

toBson

@LowLevelApi



open fun toBson(): Bson

Writes the result of simplifying to a new BSON document.

toString

abstract override fun toString(): String

JSON representation of this expression.

writeTo

@LowLevelApi



abstract override fun writeTo(writer: BsonFieldWriter)

Writes the result of simplifying this expression into writer.