Skip to content

Commit 114bbda

Browse files
committed
feat: more expr operators
Added: - $max - $min - $stdDevPop - $stdDevSamp - $sum
1 parent e2d63b0 commit 114bbda

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
@file:OptIn(ExperimentalMongodbApi::class)
2+
@file:Suppress("FunctionName")
3+
4+
package org.cufy.mongodb.expr
5+
6+
import org.cufy.bson.BsonMarker4
7+
import org.cufy.bson.array
8+
import org.cufy.bson.by
9+
import org.cufy.mongodb.*
10+
import org.cufy.mongodb.expr.Expr.*
11+
12+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/#accumulators--in-other-stages-
13+
14+
/* ============= ------------------ ============= */
15+
16+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg */
17+
@BsonMarker4
18+
fun `$avg`(array: Expr<_Array>): Expr<_Number> =
19+
Expr { `$avg` by array.element }
20+
21+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg */
22+
@BsonMarker4
23+
fun `$avg`(vararg expressions: Expr<_Number>): Expr<_Number> =
24+
Expr { `$avg` by array { expressions.forEach { by(it.element) } } }
25+
26+
/* ============= ------------------ ============= */
27+
28+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/max */
29+
@BsonMarker4
30+
fun `$max`(array: Expr<_Array>): Expr<_Element> =
31+
Expr { `$max` by array.element }
32+
33+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/max */
34+
@BsonMarker4
35+
fun `$max`(vararg expressions: Expr<_Element>): Expr<_Element> =
36+
Expr { `$max` by array { expressions.forEach { by(it.element) } } }
37+
38+
/* ============= ------------------ ============= */
39+
40+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/min */
41+
@BsonMarker4
42+
fun `$min`(array: Expr<_Array>): Expr<_Element> =
43+
Expr { `$min` by array.element }
44+
45+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/min */
46+
@BsonMarker4
47+
fun `$min`(vararg expressions: Expr<_Element>): Expr<_Element> =
48+
Expr { `$min` by array { expressions.forEach { by(it.element) } } }
49+
50+
/* ============= ------------------ ============= */
51+
52+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop */
53+
@BsonMarker4
54+
fun `$stdDevPop`(array: Expr<_Array>): Expr<_Number> =
55+
Expr { `$stdDevPop` by array.element }
56+
57+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop */
58+
@BsonMarker4
59+
fun `$stdDevPop`(vararg expressions: Expr<_Number>): Expr<_Number> =
60+
Expr { `$stdDevPop` by array { expressions.forEach { by(it.element) } } }
61+
62+
/* ============= ------------------ ============= */
63+
64+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp */
65+
@BsonMarker4
66+
fun `$stdDevSamp`(array: Expr<_Array>): Expr<_Number> =
67+
Expr { `$stdDevSamp` by array.element }
68+
69+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp */
70+
@BsonMarker4
71+
fun `$stdDevSamp`(vararg expressions: Expr<_Number>): Expr<_Number> =
72+
Expr { `$stdDevSamp` by array { expressions.forEach { by(it.element) } } }
73+
74+
/* ============= ------------------ ============= */
75+
76+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum */
77+
@BsonMarker4
78+
fun `$sum`(array: Expr<_Array>): Expr<_Number> =
79+
Expr { `$sum` by array.element }
80+
81+
/** https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum */
82+
@BsonMarker4
83+
fun `$sum`(vararg expressions: Expr<_Number>): Expr<_Number> =
84+
Expr { `$sum` by array { expressions.forEach { by(it.element) } } }
85+
86+
/* ============= ------------------ ============= */

0 commit comments

Comments
 (0)