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.
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.
opensavvy.ktmongo.dsl.aggregation.ValueDsl