Filters

object Filters

Filters extension methods to improve Kotlin interop

Since

5.3

Functions

Link copied to clipboard
fun <T> all(property: KProperty<Iterable<T>?>, vararg values: T): Bson
fun <T> all(property: KProperty<Iterable<T>?>, values: Iterable<T>): Bson

Creates a filter that matches all documents where the value of a property is an array that contains all the specified values.

Link copied to clipboard
@JvmName(name = "allvargsExt")
fun <T> KProperty<Iterable<T>?>.all(vararg values: T): Bson
@JvmName(name = "allExt")
infix fun <T> KProperty<Iterable<T>?>.all(values: Iterable<T>): Bson

Creates a filter that matches all documents where the value of a property is an array that contains all the specified values.

Link copied to clipboard
fun and(vararg filters: Bson?): Bson
fun and(filters: Iterable<Bson?>): Bson

Creates a filter that performs a logical AND of the provided list of filters. Note that this will only generate an "$and" operator if absolutely necessary, as the query language implicitly ands together all the keys. In other words, a query expression like: ``and(eq("x", 1), lt("y", 3))``

Link copied to clipboard
fun <T> bitsAllClear(property: KProperty<T?>, bitmask: Long): Bson

Creates a filter that matches all documents where all of the bit positions are clear in the property.

Link copied to clipboard
@JvmName(name = "bitsAllClearExt")
infix fun <T> KProperty<T?>.bitsAllClear(bitmask: Long): Bson

Creates a filter that matches all documents where all of the bit positions are clear in the property.

Link copied to clipboard
fun <T> bitsAllSet(property: KProperty<T?>, bitmask: Long): Bson

Creates a filter that matches all documents where all of the bit positions are set in the property.

Link copied to clipboard
@JvmName(name = "bitsAllSetExt")
infix fun <T> KProperty<T?>.bitsAllSet(bitmask: Long): Bson

Creates a filter that matches all documents where all of the bit positions are set in the property.

Link copied to clipboard
fun <T> bitsAnyClear(property: KProperty<T?>, bitmask: Long): Bson

Creates a filter that matches all documents where any of the bit positions are clear in the property.

Link copied to clipboard
@JvmName(name = "bitsAnyClearExt")
infix fun <T> KProperty<T?>.bitsAnyClear(bitmask: Long): Bson

Creates a filter that matches all documents where any of the bit positions are clear in the property.

Link copied to clipboard
fun <T> bitsAnySet(property: KProperty<T?>, bitmask: Long): Bson

Creates a filter that matches all documents where any of the bit positions are set in the property.

Link copied to clipboard
@JvmName(name = "bitsAnySetExt")
infix fun <T> KProperty<T?>.bitsAnySet(bitmask: Long): Bson

Creates a filter that matches all documents where any of the bit positions are set in the property.

Link copied to clipboard
fun <T> elemMatch(property: KProperty<Iterable<T>?>, filter: Bson): Bson

Creates a filter that matches all documents containing a property that is an array where at least one member of the array matches the given filter.

Link copied to clipboard
@JvmName(name = "elemMatchExt")
infix fun <T> KProperty<Iterable<T>?>.elemMatch(filter: Bson): Bson

Creates a filter that matches all documents containing a property that is an array where at least one member of the array matches the given filter.

Link copied to clipboard
fun <T> eq(property: KProperty<T?>, value: T?): Bson

Creates a filter that matches all documents where the value of the property equals the specified value. Note that this doesn't actually generate an $eq operator, as the query language doesn't require it.

Link copied to clipboard
@JvmName(name = "eqExt")
infix fun <T> KProperty<T?>.eq(value: T?): Bson

Creates a filter that matches all documents where the value of the property equals the specified value. Note that this doesn't actually generate an $eq operator, as the query language doesn't require it.

Link copied to clipboard
fun <T> exists(property: KProperty<T?>): Bson

Creates a filter that matches all documents that contain the given property.

fun <T> exists(property: KProperty<T?>, exists: Boolean): Bson

Creates a filter that matches all documents that either contain or do not contain the given property, depending on the value of the exists parameter.

Link copied to clipboard
@JvmName(name = "existsExt")
fun <T> KProperty<T?>.exists(): Bson

Creates a filter that matches all documents that contain the given property.

@JvmName(name = "existsExt")
infix fun <T> KProperty<T?>.exists(exists: Boolean): Bson

Creates a filter that matches all documents that either contain or do not contain the given property, depending on the value of the exists parameter.

Link copied to clipboard
fun <T> expr(expression: T): Bson

Creates a filter that matches all documents that validate against the given JSON schema document.

Link copied to clipboard
fun <T> geoIntersects(property: KProperty<T?>, geometry: Geometry): Bson
fun <T> geoIntersects(property: KProperty<T?>, geometry: Bson): Bson

Creates a filter that matches all documents containing a property with geospatial data that intersects with the specified shape.

Link copied to clipboard
@JvmName(name = "geoIntersectsExt")
infix fun <T> KProperty<T?>.geoIntersects(geometry: Geometry): Bson
@JvmName(name = "geoIntersectsExt")
infix fun <T> KProperty<T?>.geoIntersects(geometry: Bson): Bson

Creates a filter that matches all documents containing a property with geospatial data that intersects with the specified shape.

Link copied to clipboard
fun <T> geoWithin(property: KProperty<T?>, geometry: Geometry): Bson
fun <T> geoWithin(property: KProperty<T?>, geometry: Bson): Bson

Creates a filter that matches all documents containing a property with geospatial data that exists entirely within the specified shape.

Link copied to clipboard
@JvmName(name = "geoWithinExt")
infix fun <T> KProperty<T?>.geoWithin(geometry: Geometry): Bson
@JvmName(name = "geoWithinExt")
infix fun <T> KProperty<T?>.geoWithin(geometry: Bson): Bson

Creates a filter that matches all documents containing a property with geospatial data that exists entirely within the specified shape.

Link copied to clipboard
fun <T> geoWithinBox(property: KProperty<T?>, lowerLeftX: Double, lowerLeftY: Double, upperRightX: Double, upperRightY: Double): Bson

Creates a filter that matches all documents containing a property with grid coordinates data that exist entirely within the specified box.

Link copied to clipboard
@JvmName(name = "geoWithinBoxExt")
fun <T> KProperty<T?>.geoWithinBox(lowerLeftX: Double, lowerLeftY: Double, upperRightX: Double, upperRightY: Double): Bson

Creates a filter that matches all documents containing a property with grid coordinates data that exist entirely within the specified box.

Link copied to clipboard
fun <T> geoWithinCenter(property: KProperty<T?>, x: Double, y: Double, radius: Double): Bson

Creates a filter that matches all documents containing a property with grid coordinates data that exist entirely within the specified circle.

Link copied to clipboard
@JvmName(name = "geoWithinCenterExt")
fun <T> KProperty<T?>.geoWithinCenter(x: Double, y: Double, radius: Double): Bson

Creates a filter that matches all documents containing a property with grid coordinates data that exist entirely within the specified circle.

Link copied to clipboard
fun <T> geoWithinCenterSphere(property: KProperty<T?>, x: Double, y: Double, radius: Double): Bson

Creates a filter that matches all documents containing a property with geospatial data (GeoJSON or legacy coordinate pairs) that exist entirely within the specified circle, using spherical geometry. If using longitude and latitude, specify longitude first.

Link copied to clipboard
@JvmName(name = "geoWithinCenterSphereExt")
fun <T> KProperty<T?>.geoWithinCenterSphere(x: Double, y: Double, radius: Double): Bson

Creates a filter that matches all documents containing a property with geospatial data (GeoJSON or legacy coordinate pairs) that exist entirely within the specified circle, using spherical geometry. If using longitude and latitude, specify longitude first.

Link copied to clipboard
fun <T> geoWithinPolygon(property: KProperty<T?>, points: List<List<Double>>): Bson

Creates a filter that matches all documents containing a property with grid coordinates data that exist entirely within the specified polygon.

Link copied to clipboard
@JvmName(name = "geoWithinPolygonExt")
infix fun <T> KProperty<T?>.geoWithinPolygon(points: List<List<Double>>): Bson

Creates a filter that matches all documents containing a property with grid coordinates data that exist entirely within the specified polygon.

Link copied to clipboard
fun <T> gt(property: KProperty<T>, value: T): Bson

Creates a filter that matches all documents where the value of the given property is greater than the specified value.

Link copied to clipboard
@JvmName(name = "gtExt")
infix fun <T> KProperty<T>.gt(value: T): Bson

Creates a filter that matches all documents where the value of the given property is greater than the specified value.

Link copied to clipboard
fun <T> gte(property: KProperty<T>, value: T): Bson

Creates a filter that matches all documents where the value of the given property is greater than or equal to the specified value.

Link copied to clipboard
@JvmName(name = "gteExt")
infix fun <T> KProperty<T>.gte(value: T): Bson

Creates a filter that matches all documents where the value of the given property is greater than or equal to the specified value.

Link copied to clipboard
fun <T> in(property: KProperty<T?>, values: Iterable<T?>): Bson
@JvmName(name = "inIterable")
fun <T> in(property: KProperty<Iterable<T>?>, values: Iterable<T?>): Bson

Creates a filter that matches all documents where the value of a property equals any value in the list of specified values.

Link copied to clipboard
@JvmName(name = "inExt")
infix fun <T> KProperty<T?>.in(values: Iterable<T?>): Bson
@JvmName(name = "inIterableExt")
infix fun <T> KProperty<Iterable<T>?>.in(values: Iterable<T?>): Bson

Creates a filter that matches all documents where the value of a property equals any value in the list of specified values.

Link copied to clipboard
fun jsonSchema(schema: Bson): Bson

Creates a filter that matches all documents that validate against the given JSON schema document.

Link copied to clipboard
fun <T> lt(property: KProperty<T?>, value: T): Bson

Creates a filter that matches all documents where the value of the given property is less than the specified value.

Link copied to clipboard
@JvmName(name = "ltExt")
infix fun <T> KProperty<T?>.lt(value: T): Bson

Creates a filter that matches all documents where the value of the given property is less than the specified value.

Link copied to clipboard
fun <T> lte(property: KProperty<T?>, value: T): Bson

Creates a filter that matches all documents where the value of the given property is less than or equal to the specified value.

Link copied to clipboard
@JvmName(name = "lteExt")
infix fun <T> KProperty<T?>.lte(value: T): Bson

Creates a filter that matches all documents where the value of the given property is less than or equal to the specified value.

Link copied to clipboard
fun <T> mod(property: KProperty<T?>, divisor: Long, remainder: Long): Bson

Creates a filter that matches all documents where the value of a property divided by a divisor has the specified remainder (i.e. perform a modulo operation to select documents).

Link copied to clipboard
@JvmName(name = "modExt")
fun <T> KProperty<T?>.mod(divisor: Long, remainder: Long): Bson

Creates a filter that matches all documents where the value of a property divided by a divisor has the specified remainder (i.e. perform a modulo operation to select documents).

Link copied to clipboard
fun <T> ne(property: KProperty<T?>, value: T?): Bson

Creates a filter that matches all documents where the value of the property does not equal the specified value.

Link copied to clipboard
@JvmName(name = "neExt")
infix fun <T> KProperty<T?>.ne(value: T?): Bson

Creates a filter that matches all documents where the value of the property does not equal the specified value.

Link copied to clipboard
fun <T> near(property: KProperty<T?>, geometry: Point, maxDistance: Double? = null, minDistance: Double? = null): Bson
fun <T> near(property: KProperty<T?>, geometry: Bson, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified GeoJSON point.

fun <T> near(property: KProperty<T?>, x: Double, y: Double, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified point.

Link copied to clipboard
@JvmName(name = "nearExt")
fun <T> KProperty<T?>.near(geometry: Point, maxDistance: Double? = null, minDistance: Double? = null): Bson
@JvmName(name = "nearExt")
fun <T> KProperty<T?>.near(geometry: Bson, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified GeoJSON point.

@JvmName(name = "nearExt")
fun <T> KProperty<T?>.near(x: Double, y: Double, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified point.

Link copied to clipboard
fun <T> nearSphere(property: KProperty<T?>, geometry: Point, maxDistance: Double? = null, minDistance: Double? = null): Bson
fun <T> nearSphere(property: KProperty<T?>, geometry: Bson, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified GeoJSON point using spherical geometry.

fun <T> nearSphere(property: KProperty<T?>, x: Double, y: Double, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified point using spherical geometry.

Link copied to clipboard
@JvmName(name = "nearSphereExt")
fun <T> KProperty<T?>.nearSphere(geometry: Point, maxDistance: Double? = null, minDistance: Double? = null): Bson
@JvmName(name = "nearSphereExt")
fun <T> KProperty<T?>.nearSphere(geometry: Bson, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified GeoJSON point using spherical geometry.

@JvmName(name = "nearSphereExt")
fun <T> KProperty<T?>.nearSphere(x: Double, y: Double, maxDistance: Double? = null, minDistance: Double? = null): Bson

Creates a filter that matches all documents containing a property with geospatial data that is near the specified point using spherical geometry.

Link copied to clipboard
fun <T> nin(property: KProperty<T?>, values: Iterable<T?>): Bson
@JvmName(name = "ninIterable")
fun <T> nin(property: KProperty<Iterable<T>?>, values: Iterable<T?>): Bson

Creates a filter that matches all documents where the value of a property does not equal any of the specified values or does not exist.

Link copied to clipboard
@JvmName(name = "ninExt")
infix fun <T> KProperty<T?>.nin(values: Iterable<T?>): Bson
@JvmName(name = "ninIterableExt")
infix fun <T> KProperty<Iterable<T>?>.nin(values: Iterable<T?>): Bson

Creates a filter that matches all documents where the value of a property does not equal any of the specified values or does not exist.

Link copied to clipboard
fun nor(vararg filters: Bson): Bson
fun nor(filters: Iterable<Bson>): Bson

Creates a filter that performs a logical NOR operation on all the specified filters.

Link copied to clipboard
fun not(filter: Bson): Bson

Creates a filter that matches all documents that do not match the passed in filter. Requires the property to passed as part of the value passed in and lifts it to create a valid "$not" query: ``not(eq("x", 1))``

Link copied to clipboard
fun or(vararg filters: Bson?): Bson
fun or(filters: Iterable<Bson?>): Bson

Creates a filter that preforms a logical OR of the provided list of filters.

Link copied to clipboard
fun regex(property: KProperty<String?>, pattern: Pattern): Bson
fun regex(property: KProperty<String?>, pattern: String): Bson
fun regex(property: KProperty<String?>, regex: Regex): Bson
@JvmName(name = "regexIterable")
fun regex(property: KProperty<Iterable<String?>>, pattern: Pattern): Bson
@JvmName(name = "regexIterable")
fun regex(property: KProperty<Iterable<String?>>, pattern: String): Bson
@JvmName(name = "regexIterable")
fun regex(property: KProperty<Iterable<String?>>, regex: Regex): Bson

Creates a filter that matches all documents where the value of the property matches the given regular expression pattern.

fun regex(property: KProperty<String?>, pattern: String, options: String): Bson
@JvmName(name = "regexIterable")
fun regex(property: KProperty<Iterable<String?>>, regex: String, options: String): Bson

Creates a filter that matches all documents where the value of the option matches the given regular expression pattern with the given options applied.

Link copied to clipboard
@JvmName(name = "regexExt")
infix fun KProperty<String?>.regex(pattern: Pattern): Bson
@JvmName(name = "regexExt")
infix fun KProperty<String?>.regex(pattern: String): Bson
@JvmName(name = "regexExt")
infix fun KProperty<String?>.regex(regex: Regex): Bson
@JvmName(name = "regexIterableExt")
infix fun KProperty<Iterable<String?>>.regex(pattern: Pattern): Bson
@JvmName(name = "regexIterableExt")
infix fun KProperty<Iterable<String?>>.regex(pattern: String): Bson
@JvmName(name = "regexIterableExt")
infix fun KProperty<Iterable<String?>>.regex(regex: Regex): Bson

Creates a filter that matches all documents where the value of the property matches the given regular expression pattern.

@JvmName(name = "regexExt")
fun KProperty<String?>.regex(pattern: String, options: String): Bson
@JvmName(name = "regexIterableExt")
fun KProperty<Iterable<String?>>.regex(regex: String, options: String): Bson

Creates a filter that matches all documents where the value of the option matches the given regular expression pattern with the given options applied.

Link copied to clipboard
fun <T> size(property: KProperty<T?>, size: Int): Bson

Creates a filter that matches all documents where the value of a property is an array of the specified size.

Link copied to clipboard
@JvmName(name = "sizeExt")
infix fun <T> KProperty<T?>.size(size: Int): Bson

Creates a filter that matches all documents where the value of a property is an array of the specified size.

Link copied to clipboard
fun text(search: String, textSearchOptions: TextSearchOptions = TextSearchOptions()): Bson

Creates a filter that matches all documents matching the given the search term with the given text search options.

Link copied to clipboard
fun <T> type(property: KProperty<T?>, type: BsonType): Bson

Creates a filter that matches all documents where the value of the property is of the specified BSON type.

Link copied to clipboard
@JvmName(name = "typeExt")
infix fun <T> KProperty<T?>.type(type: BsonType): Bson

Creates a filter that matches all documents where the value of the property is of the specified BSON type.

Link copied to clipboard
fun where(javaScriptExpression: String): Bson

Creates a filter that matches all documents for which the given expression is true.