Projections

Projection extension methods to improve Kotlin interop

Since

5.3

Functions

Link copied to clipboard
fun computed(property: String, expression: Any): Bson

Creates a projection of a String whose value is computed from the given expression. Projection with an expression can be used in the following contexts:

fun <T> computed(property: KProperty<T>, expression: Any): Bson

Creates a projection of a property whose value is computed from the given expression. Projection with an expression can be used in the following contexts:

Link copied to clipboard
@JvmName(name = "computedFromExt")
infix fun String.computed(expression: Any): Bson

Creates a projection of a String whose value is computed from the given expression. Projection with an expression can be used in the following contexts:

@JvmName(name = "computedFromExt")
infix fun <T> KProperty<T>.computed(expression: Any): Bson

Creates a projection of a property whose value is computed from the given expression. Projection with an expression can be used in the following contexts:

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

Creates a projection of a property whose value is equal to the {@code $$SEARCH_META} variable. for use with {@link Aggregates#search(SearchOperator, SearchOptions)} / {@link Aggregates#search(SearchCollector, SearchOptions)}. Calling this method is equivalent to calling {@link #computed(String, Object)} with {@code "$$SEARCH_META"} as the second argument.

Link copied to clipboard
@JvmName(name = "computedSearchMetaExt")
fun <T> KProperty<T>.computedSearchMeta(): Bson

Creates a projection of a property whose value is equal to the {@code $$SEARCH_META} variable. for use with {@link Aggregates#search(SearchOperator, SearchOptions)} / {@link Aggregates#search(SearchCollector, SearchOptions)}. Calling this method is equivalent to calling {@link #computed(String, Object)} with {@code "$$SEARCH_META"} as the second argument.

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

Creates a projection that includes for the given property only the first element of the array value of that field that matches the given query filter.

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

Creates a projection that includes for the given property only the first element of the array value of that field that matches the given query filter.

Link copied to clipboard
fun exclude(vararg properties: KProperty<*>): Bson
fun exclude(properties: Iterable<KProperty<*>>): Bson

Creates a projection that excludes all of the given properties.

Link copied to clipboard
fun excludeId(): Bson

Creates a projection that excludes the _id field. This suppresses the automatic inclusion of _id that is the default, even when other fields are explicitly included.

Link copied to clipboard
fun fields(vararg projections: Bson): Bson
fun fields(projections: List<Bson>): Bson

Creates a projection that combines the list of projections into a single one. If there are duplicate keys, the last one takes precedence.

Link copied to clipboard
fun include(vararg properties: KProperty<*>): Bson
fun include(properties: Iterable<KProperty<*>>): Bson

Creates a projection that includes all of the given properties.

Link copied to clipboard
fun <T> meta(property: KProperty<T>, metaFieldName: String): Bson

Creates a $meta projection for the given property

Link copied to clipboard
@JvmName(name = "metaExt")
infix fun <T> KProperty<T>.meta(metaFieldName: String): Bson

Creates a $meta projection for the given property

Link copied to clipboard

Creates a searchHighlights projection for the given property, for use with {@link Aggregates#search(SearchOperator, SearchOptions)} / {@link Aggregates#search(SearchCollector, SearchOptions)}. Calling this method is equivalent to calling {@link #meta(String, String)} with {@code "searchHighlights"} as the argument.

Link copied to clipboard
fun <T> KProperty<T>.metaSearchScore(): Bson

Creates a searchScore projection for the given property, for use with {@link Aggregates#search(SearchOperator, SearchOptions)} / {@link Aggregates#search(SearchCollector, SearchOptions)}. Calling this method is equivalent to calling {@link #meta(String, String)} with {@code "searchScore"} as the argument.

Link copied to clipboard
fun <T> KProperty<T>.metaTextScore(): Bson

Creates a textScore projection for the given property, for use with text queries. Calling this method is equivalent to calling {@link #meta(String)} with {@code "textScore"} as the argument.

Link copied to clipboard
@Beta(value = [Reason.SERVER])
fun <T> KProperty<T>.metaVectorSearchScore(): Bson

Creates a vectorSearchScore projection for the given property, for use with {@link Aggregates#vectorSearch(FieldSearchPath, Iterable, String, long, VectorSearchOptions)} . Calling this method is equivalent to calling {@link #meta(String, String)} with {@code "vectorSearchScore"} as the argument.

Link copied to clipboard

In order to write $p.p2

Link copied to clipboard
infix fun <T> KProperty<T>.slice(limit: Int): Bson
fun <T> KProperty<T>.slice(skip: Int, limit: Int): Bson

Creates a projection to the given property of a slice of the array value of that field.

Properties

Link copied to clipboard
val <T> KProperty<T>.elemMatch: Bson

Creates a projection that includes for the given property only the first element of an array that matches the query filter. This is referred to as the positional $ operator.

Link copied to clipboard

The projection of the property.

The projection of the property. This is used in an aggregation pipeline to reference a property from a path.