Skip to content

opensavvy.ktmongo.dsl.path

Utilities for referencing variables and classes.

User::_id                          // _id
User::profile / Profile::name      // profile.name
User::friends[1] / Friend::name    // friends.$1.name

This package contains a low-level type-unsafe implementation of arbitrary document paths, and a high-level type-safe wrapper that provides the above utility functions.

Note that some functions are only provided when the FieldDsl is into scope (which should be done automatically by most operators). This means that you should rarely need to import anything for these functions to be available.

Operators

  • opensavvy.ktmongo.dsl.path.Field.div

  • opensavvy.ktmongo.dsl.path.get

Types

Field

interface Field<in Root, out Type>

High-level, typesafe pointer to a specific field in a document.

FieldDsl

interface FieldDsl

Operators to construct MongoDB field references from Kotlin code.

Path

@LowLevelApi



data class Path(val segment: PathSegment, val parent: Path?)

Low-level, type-unsafe pointer to a specific field in a document.

PathSegment

@LowLevelApi



sealed class PathSegment

Single segment in a Path.

PropertyNameStrategy

Allows configuring how the DSL generates property paths from

Functions

at

infix inline fun <T> Bson.at(field: Field<*, T>): T

Finds the first value that matches path in a given BSON document.

select

inline fun <T> Bson.select(field: Field<*, T>): Sequence<T>

Finds all values that match field in a given BSON document.

selectFirst

inline fun <T> Bson.selectFirst(field: Field<*, T>): T

Finds the first value that matches field in a given BSON document.