Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryFilterQueryPredicate

FilterQueryPredicate

DSL for MongoDB operators that are used as predicates in conditions in a context where the targeted field is already specified.

Example

class User(
    val name: String?,
    val age: Int,
)

collection.find {
    User::name { //(1)
        eq("foo")
    }
}
  1. By referring to a specific property, we obtain a FilterQueryPredicate that we can use to declare many operators on that property.

If you can't find the operator you're searching for, visit the tracking issue.

External resources

Parameters

T

The type on which this predicate applies. For example, if the selected field is of type String, then T is String.

Properties

context

abstract val context: 

The context used to generate this expression.

field

Converts a Kotlin property into a Field.

Functions

accept

abstract override fun accept(node: BsonNode)

Adds a new node as a child of this one.

acceptAll

fun <N : Node> CompoundNode<N>.acceptAll(nodes: Iterable<N>)

Adds any number of nodes into this one.

bitsAllClear

abstract fun bitsAllClear(mask: )

Matches documents where all bit positions present in mask are clear (i.e., 0) in the current field.

abstract fun bitsAllClear(mask: ByteArray)

Matches documents where all bit positions present in mask are clear (i.e., 0) in the current field.

bitsAllSet

abstract fun bitsAllSet(mask: )

Matches documents where all bit positions present in mask are set (i.e., 1) in the current field.

abstract fun bitsAllSet(mask: ByteArray)

Matches documents where all bit positions present in mask are set (i.e., 1) in the current field.

bitsAnyClear

abstract fun bitsAnyClear(mask: )

Matches documents where any bit position present in mask is clear (i.e., 0) in the current field.

abstract fun bitsAnyClear(mask: ByteArray)

Matches documents where any bit position present in mask is clear (i.e., 0) in the current field.

bitsAnySet

abstract fun bitsAnySet(mask: )

Matches documents where any bit position present in mask is set (i.e., 1) in the current field.

abstract fun bitsAnySet(mask: ByteArray)

Matches documents where any bit position present in mask is set (i.e., 1) in the current field.

div

open operator fun <Root, Parent, Child> KProperty1<Root, Parent>.div(child: KProperty1<Parent & Any, Child>): Field<Root, Child>

Refers to child as a nested field of the current field.

doesNotExist

abstract fun doesNotExist()

Matches documents that do not contain the specified field. Documents where the field if null are counted as existing.

eq

abstract fun eq(value: T)

Matches documents where the value of a field equals the value.

eqNotNull

open fun eqNotNull(value: T?)

Matches documents where the value of a field equals value.

exists

abstract fun exists()

Matches documents that contain the specified field, including values where the field value is null.

freeze

abstract override fun freeze()

Makes this expression immutable.

get

open operator fun <Root, Type> KProperty1<Root, Collection<Type>>.get(index: Int): Field<Root, Type>

Refers to a specific item in an array, by its index.

open operator fun <Root, Type> KProperty1<Root, Map<String, Type>>.get(index: String): Field<Root, Type>

Refers to a specific item in a map, by its name.

gt

abstract fun gt(value: T)

Selects documents for which this field has a value strictly greater than value.

gte

abstract fun gte(value: T)

Selects documents for which this field has a value greater or equal to value.

gteNotNull

open fun gteNotNull(value: T?)

Selects documents for which this field has a value greater or equal to value.

gtNotNull

open fun gtNotNull(value: T?)

Selects documents for which this field has a value strictly greater than value.

hasType

abstract fun hasType(type: )

Selects documents where the value of the field is an instance of the specified BSON type.

isNotNull

open fun isNotNull()

Selects documents for which the field is not null.

isNotOneOf

open fun isNotOneOf(vararg values: T)

Selects documents for which this field is not equal to any of the given values.

abstract fun isNotOneOf(values: Collection<T>)

Selects documents for which this field is not equal to any of the given values.

isNotUndefined

open fun isNotUndefined()

Selects documents for which the field is not undefined.

isNull

open fun isNull()

Selects documents for which the field is null.

isOneOf

open fun isOneOf(vararg values: T)

Selects documents for which this field is equal to one of the given values.

abstract fun isOneOf(values: Collection<T>)

Selects documents for which this field is equal to one of the given values.

isUndefined

open fun isUndefined()

Selects documents for which the field is undefined.

lt

abstract fun lt(value: T)

Selects documents for which this field has a value strictly lesser than value.

lte

abstract fun lte(value: T)

Selects documents for which this field has a value lesser or equal to value.

lteNotNull

open fun lteNotNull(value: T?)

Selects documents for which this field has a value lesser or equal to value.

ltNotNull

open fun ltNotNull(value: T?)

Selects documents for which this field has a value strictly lesser than value.

ne

abstract fun ne(value: T)

Matches documents where the value of a field does not equal the value.

not

abstract fun not(expression: FilterQueryPredicate<T>.() -> Unit)

Performs a logical NOT operation on the specified expression and selects the documents that do not match the expression. This includes the elements that do not contain the field.

regex

abstract fun regex(pattern: String, caseInsensitive: Boolean = false, dotAll: Boolean = false, extended: Boolean = false, matchEachLine: Boolean = false)

Matches documents where the field corresponds to a given regex expression.

simplify

abstract fun simplify(): BsonNode?

Returns a simplified (but equivalent) expression to the current expression.

toBson

open fun toBson(): 

Writes the result of simplifying to a new Bson.

toString

abstract override fun toString(): String

JSON representation of this expression.

writeTo

abstract fun writeTo(writer: )

Writes the result of simplifying this expression into writer.