Skip to content

Commit e97f1eb

Browse files
committed
feat: $filter and $map overloads
1 parent 114bbda commit e97f1eb

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • module-mongokt/src/commonMain/kotlin/expr

module-mongokt/src/commonMain/kotlin/expr/_Array.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ fun `$concatArrays`(arrays: List<Expr<_Array>>): Expr<_Array> =
3939

4040
/* ============= ------------------ ============= */
4141

42+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ */
43+
@BsonMarker4
44+
fun `$filter`(
45+
input: Expr<_Array>,
46+
cond: Expr<_Boolean>,
47+
limit: Expr<_Number>? = null,
48+
): Expr<_Array> = Expr {
49+
`$filter` by {
50+
"input" by input.element
51+
"cond" by cond.element
52+
if (limit != null) "limit" by limit.element
53+
}
54+
}
55+
4256
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ */
4357
@Suppress("LocalVariableName")
4458
@BsonMarker4
@@ -133,6 +147,19 @@ fun `$lastN`(input: Expr<_Array>, n: Expr<_Number>): Expr<_Array> =
133147

134148
/* ============= ------------------ ============= */
135149

150+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ */
151+
@Suppress("LocalVariableName")
152+
@BsonMarker4
153+
fun `$map`(
154+
input: Expr<_Array>,
155+
_in: Expr<_Element>,
156+
): Expr<_Array> = Expr {
157+
`$map` by {
158+
"input" by input.element
159+
"in" by _in.element
160+
}
161+
}
162+
136163
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ */
137164
@Suppress("LocalVariableName")
138165
@BsonMarker4

0 commit comments

Comments
 (0)