Skip to content

CompoundNode

interface CompoundNode<N : Node> : Node

A Node that combines multiple other nodes into a single node.

A compound node may have 0.n children. Children are added by calling the accept method.

Accepted children must follow a few invariants. See Node for more information.

There are no general-purpose way of accessing the children after they have been accepted. Instead, this node should be considered as representing the children itself, as a single unit. Subtypes may decide to provide such a feature, however.

Inheritors

Functions

accept

@LowLevelApi
@DangerousMongoApi
abstract fun accept(node: N)

Adds a new Node into the current node.

This method is considered unsafe as it allows inserting arbitrary nodes into the current node. Since KtMongo is a database driver, this method allows inserting any kind of operation without checking any security or coherence invariants.

If you are not careful, this method will create database injection risks.

Users should only interact with this method when they have a custom node that doesn't exist in the library, for example, when adding a missing operator. In these cases, we highly recommend users to contact the maintainers of KtMongo to ensure the created operator respects all invariants. If possible, upstreaming the operator would be of benefit to all users and guarantees future bug fixes.

In all other cases, it is expected that implementations of this interface provide methods for each added functionality that are responsible for checking invariants and are safe to call.

For a more detailed explanation of the contract of this method, see Node.

Implementation notes

acceptAll

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 fun freeze()

Makes this node immutable.

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

To learn more about this process, see Node.

Thread-safety

Instances of <strong>Node</strong> are not thread-safe before <strong>freeze</strong> has been called.

Once the freeze function has returned, then the node must be immutable and thread-safe.