HasMatch¶
Pipeline implementing the $match stage.
Inheritors¶
Properties¶
context¶
@LowLevelApi
abstract val context: BsonContext
The context used to generate this pipeline.
Functions¶
match¶
Filters documents based on a specified filter.
Matched documents are passed to the next pipeline stage.
Pipeline optimization
Place the match call as early in the pipeline as possible. Because match limits the total number of elements being processed, earlier match operations minimize the amount of processing down the pipe.
If you place a match at the very beginning of a pipeline, the query can take advantage of indexes.
External resources
matchExpr¶
Filters documents based on a specific filter, written using aggregation syntax.
Matched documents are passed to the next pipeline stage.
This method is a helper to combine the match stage with the expr operator.
Example
Find all incoherent users: users modified before they were created.
class User(
val _id: ObjectId,
val creationDate: Instant,
val modificationDate: Instant,
)
val incoherent = users.aggregate()
.matchExpr { User::modificationDate lt User::creationDate }
.toList()
The above query is syntax sugar for this identical query:
val incoherent = users.aggregate()
.match {
expr { User::modificationDate lt User::creationDate }
}
.toList()
See also
-
match: The$matchstage. -
FilterQuery.expr: The$exproperator, allowing to use aggregation syntax in a filter.
toString¶
unsafeCast¶
abstract fun <New : Any> unsafeCast(): Pipeline<New>
Changes the type of the returned document, with no type-safety.
withStage¶
@DangerousMongoApi
@LowLevelApi
abstract fun withStage(stage: BsonNode): Pipeline<Document>
Creates a new pipeline that expands on the current one by adding stage.
writeTo¶
@LowLevelApi
abstract fun writeTo(writer: BsonValueWriter)
Writes the entire pipeline into writer.