Skip to content

CompoundNode

interface CompoundNode<N : 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 generally considered unsafe, as it allows inserting any kind of node into the current node. Since this library is about representing database requests, this method allows inserting any kind of operation, without necessarily checking any security or coherence invariants.

Users should only interact with this method when they add a new type of node that doesn't exist in the library. For example, when adding an operator that is missing from the library. 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.

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.