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

The $match stage.

The $expr operator, allowing to use aggregation syntax in a filter.