MongoDB request DSL

Pure Kotlin DSL targeting all MongoDB operators.

Pure Kotlin implementation of MongoDB operators, based on dev.opensavvy.ktmongo:bson. All platforms supported by :bson are also supported by this module.

It is not expected that end-users will have a direct dependency on this module. Instead, we expect end-users to have a dependency on one of the "driver" modules: driver-sync or driver-coroutines.

Introduction

No matter whether you use the synchronous or the coroutines drivers, you must construct BSON instances to communicate with MongoDB. While the :bson module allows writing arbitrary BSON, it is rather low-level and requires to take care of escaping as well as remembering the syntax for each operator. This module provides a Kotlin function for each MongoDB operator:

collection.find {
User::score isOneOf listOf(4, 5)
User::age gte 18
}

To learn more about the Class::field syntax, and how to refer to fields in general, see Field.

Operator DSLs

Operators are organized by the context in which they are available in. For example, the $eq operator cannot be used in an update's modification field, but it can be used in an update's filter field.

Instances of these classes are usually provided by the driver as part of its functions.

  • Filter operators

  • opensavvy.ktmongo.dsl.query.UpdateOperators

  • opensavvy.ktmongo.dsl.query.UpsertOperators

To create a custom operator (for example because it isn't part of the library yet), see opensavvy.ktmongo.dsl.query.common.AbstractExpression.

Aggregation DSLs

KtMongo has support for aggregation pipelines through dedicated DSLs.

Packages

Link copied to clipboard

Annotations and other global concepts.

Link copied to clipboard

Aggregation pipelines are powerful ways to query and update MongoDB documents. Compared to regular queries, aggregation pipelines can perform more complex operations, can compare fields from the same document together, or combine data from other sources.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Utilities for referencing variables and classes.

Link copied to clipboard

Operators, classified by the context in which they are available in.

Link copied to clipboard

Helpers to represent trees of data built bottom-up. Nodes become immutable when they become branches of another tree, and offer utilities for debugging (e.g. JSON representation in their toString implementation).