Skip to content

Value

interface Value<in Root : Any, out Type> : Node, BsonValueWriteable

An intermediary value in an aggregation expression.

Each implementation of this interface is a logical BSON node in our own intermediate representation. Each node knows how to writeTo itself into a BSON document.

Instances of this interface are obtained by the end-user through the AggregationOperators builder. Functions from KtMongo which expect aggregation values provide an instance of AggregationOperators into scope automatically. For example, see FilterQuery.expr.

Difference with Expression

This interface and its hierarchy mimic BsonNode. The main difference is the expected context: BsonNode represents an operator, which is stored as a BSON document and doesn't participate in any type hierarchy. Instead, Value is stored as a BSON value and its return type can be further embedded into more values.

Security

Implementing this interface allows injecting arbitrary BSON into a request. Be very careful not to make injections possible.

Implementation notes

Prefer implementing AbstractValue instead of implementing this interface directly.

Debugging notes

Use toString to view the JSON representation of this expression.

See also

Inheritors

Properties

context

@LowLevelApi



abstract val context: BsonContext

The context used to generate this value.

Functions

freeze

@LowLevelApi



abstract override fun freeze()

Makes this value immutable.

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

simplify

@LowLevelApi



abstract fun simplify(): Value<Root, Type>

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

toString

abstract override fun toString(): String

JSON representation of this expression.

Note that since this class represents a BSON value, and BSON libraries often only support documents, the actual value may be surrounded by some boilerplate (like an array or a useless value).

writeTo

@LowLevelApi



abstract override fun writeTo(writer: BsonValueWriter)

Writes the result of simplifying this value into writer.