let

abstract fun <T> let(value: Value<LocalDocument, T>, name: String?): Value<ForeignDocument, T>(source)
@JvmName(name = "letByField")
open fun <T> let(value: Field<LocalDocument, T>, name: String?): Value<ForeignDocument, T>(source)
@JvmName(name = "letByProperty")
open fun <T> let(value: KProperty1<LocalDocument, T>, name: String?): Value<ForeignDocument, T>(source)
inline fun <T> let(value: T, name: String?): Value<ForeignDocument, T>(source)

Creates a binding allowing to use an arbitrary value computed from the local documents within the foreign pipeline.

By default, when using a pipeline in from, each foreign pipeline computes the exact same results. Using let, we can inject an arbitrary value within any stage of the foreign pipeline to force it to return different results.

Example

class Department(
val _id: ObjectId,
val name: String,
val creationDate: Instant,
)

class User(
val _id: ObjectId,
val name: String,
val creationDate: Instant,
val departments: List<Department>,
)

users.aggregate()
.lookup {
into(User::departments)

val userCreationDate = let(User::creationDate)

from(
departments.aggregate()
.matchExpr { Department::creationDate gte userCreationDate }
)
}

To perform a simple equality between one local and one foreign field, see on.

External resources

Parameters

name

The name of the generated variable. If null, a name is generated automatically.


@JvmName(name = "letByField")
open fun <T> let(value: Field<LocalDocument, T>): Value<ForeignDocument, T>(source)
@JvmName(name = "letByProperty")
open fun <T> let(value: KProperty1<LocalDocument, T>): Value<ForeignDocument, T>(source)
inline fun <T> let(value: T): Value<ForeignDocument, T>(source)

Creates a binding allowing to use an arbitrary value computed from the local documents within the foreign pipeline.

By default, when using a pipeline in from, each foreign pipeline computes the exact same results. Using let, we can inject an arbitrary value within any stage of the foreign pipeline to force it to return different results.

Example

class Department(
val _id: ObjectId,
val name: String,
val creationDate: Instant,
)

class User(
val _id: ObjectId,
val name: String,
val creationDate: Instant,
val departments: List<Department>,
)

users.aggregate()
.lookup {
into(User::departments)

val userCreationDate = let(User::creationDate)

from(
departments.aggregate()
.matchExpr { Department::creationDate gte userCreationDate }
)
}

To perform a simple equality between one local and one foreign field, see on.

External resources