-
-
Notifications
You must be signed in to change notification settings - Fork 509
/
Copy pathExpr.php
1685 lines (1539 loc) · 56.3 KB
/
Expr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
namespace Doctrine\ODM\MongoDB\Aggregation;
use BadMethodCallException;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Persisters\DocumentPersister;
use Doctrine\ODM\MongoDB\Types\Type;
use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use LogicException;
use function array_map;
use function array_merge;
use function assert;
use function func_get_args;
use function is_array;
use function is_string;
use function substr;
/**
* Fluent interface for building aggregation pipelines.
*/
class Expr
{
/** @var DocumentManager */
private $dm;
/** @var ClassMetadata */
private $class;
/** @var array */
private $expr = [];
/**
* The current field we are operating on.
*
* @var string
*/
private $currentField;
/** @var array|null */
private $switchBranch;
public function __construct(DocumentManager $dm, ClassMetadataInterface $class)
{
assert($class instanceof ClassMetadata);
$this->dm = $dm;
$this->class = $class;
}
/**
* Returns the absolute value of a number.
*
* The <number> argument can be any valid expression as long as it resolves
* to a number.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/abs/
*
* @param mixed|self $number
*/
public function abs($number): self
{
return $this->operator('$abs', $number);
}
/**
* Adds numbers together or adds numbers and a date. If one of the arguments
* is a date, $add treats the other arguments as milliseconds to add to the
* date.
*
* The arguments can be any valid expression as long as they resolve to
* either all numbers or to numbers and a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/add/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
* @param mixed|self ...$expressions Additional expressions
*/
public function add($expression1, $expression2, ...$expressions): self
{
return $this->operator('$add', func_get_args());
}
/**
* Adds one or more $and clauses to the current expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/and/
*
* @param array|self $expression
* @param array|self ...$expressions
*/
public function addAnd($expression, ...$expressions): self
{
if (! isset($this->expr['$and'])) {
$this->expr['$and'] = [];
}
$this->expr['$and'] = array_merge($this->expr['$and'], array_map([$this, 'ensureArray'], func_get_args()));
return $this;
}
/**
* Adds one or more $or clause to the current expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/or/
*
* @param array|self $expression
* @param array|self ...$expressions
*/
public function addOr($expression, ...$expressions): self
{
if (! isset($this->expr['$or'])) {
$this->expr['$or'] = [];
}
$this->expr['$or'] = array_merge($this->expr['$or'], array_map([$this, 'ensureArray'], func_get_args()));
return $this;
}
/**
* Returns an array of all unique values that results from applying an
* expression to each document in a group of documents that share the same
* group by key. Order of the elements in the output array is unspecified.
*
* AddToSet is an accumulator operation only available in the group stage.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/addToSet/
*
* @param mixed|self $expression
*/
public function addToSet($expression): self
{
return $this->operator('$addToSet', $expression);
}
/**
* Evaluates an array as a set and returns true if no element in the array
* is false. Otherwise, returns false. An empty array returns true.
*
* The expression must resolve to an array.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/allElementsTrue/
*
* @param mixed|self $expression
*/
public function allElementsTrue($expression): self
{
return $this->operator('$allElementsTrue', $expression);
}
/**
* Evaluates an array as a set and returns true if any of the elements are
* true and false otherwise. An empty array returns false.
*
* The expression must resolve to an array.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/anyElementTrue/
*
* @param array|self $expression
*/
public function anyElementTrue($expression): self
{
return $this->operator('$anyElementTrue', $expression);
}
/**
* Returns the element at the specified array index.
*
* The <array> expression can be any valid expression as long as it resolves
* to an array.
* The <idx> expression can be any valid expression as long as it resolves
* to an integer.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/arrayElemAt/
*
* @param mixed|self $array
* @param mixed|self $index
*/
public function arrayElemAt($array, $index): self
{
return $this->operator('$arrayElemAt', [$array, $index]);
}
/**
* Returns the average value of the numeric values that result from applying
* a specified expression to each document in a group of documents that
* share the same group by key. Ignores nun-numeric values.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/avg/
*
* @param mixed|self $expression
*/
public function avg($expression): self
{
return $this->operator('$avg', $expression);
}
/**
* Adds a case statement for a branch of the $switch operator.
*
* Requires {@link switch()} to be called first. The argument can be any
* valid expression that resolves to a boolean. If the result is not a
* boolean, it is coerced to a boolean value.
*
* @param mixed|self $expression
*/
public function case($expression): self
{
$this->requiresSwitchStatement(static::class . '::case');
$this->switchBranch = ['case' => $expression];
return $this;
}
/**
* Returns the smallest integer greater than or equal to the specified number.
*
* The <number> expression can be any valid expression as long as it
* resolves to a number.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/ceil/
*
* @param mixed|self $number
*/
public function ceil($number): self
{
return $this->operator('$ceil', $number);
}
/**
* Compares two values and returns:
* -1 if the first value is less than the second.
* 1 if the first value is greater than the second.
* 0 if the two values are equivalent.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/cmp/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function cmp($expression1, $expression2): self
{
return $this->operator('$cmp', [$expression1, $expression2]);
}
/**
* Concatenates strings and returns the concatenated string.
*
* The arguments can be any valid expression as long as they resolve to
* strings. If the argument resolves to a value of null or refers to a field
* that is missing, $concat returns null.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/concat/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
* @param mixed|self ...$expressions Additional expressions
*/
public function concat($expression1, $expression2, ...$expressions): self
{
return $this->operator('$concat', func_get_args());
}
/**
* Concatenates arrays to return the concatenated array.
*
* The <array> expressions can be any valid expression as long as they
* resolve to an array.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/concatArrays/
*
* @param mixed|self $array1
* @param mixed|self $array2
* @param mixed|self ...$arrays Additional expressions
*/
public function concatArrays($array1, $array2, ...$arrays): self
{
return $this->operator('$concatArrays', func_get_args());
}
/**
* Evaluates a boolean expression to return one of the two specified return
* expressions.
*
* The arguments can be any valid expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/cond/
*
* @param mixed|self $if
* @param mixed|self $then
* @param mixed|self $else
*/
public function cond($if, $then, $else): self
{
return $this->operator('$cond', ['if' => $if, 'then' => $then, 'else' => $else]);
}
/**
* Converts an expression object into an array, recursing into nested items
*
* For expression objects, it calls getExpression on the expression object.
* For arrays, it recursively calls itself for each array item. Other values
* are returned directly.
*
* @internal
*
* @param mixed|self $expression
*
* @return string|array
*/
public static function convertExpression($expression)
{
if (is_array($expression)) {
return array_map(static function ($expression) {
return static::convertExpression($expression);
}, $expression);
}
if ($expression instanceof self) {
return $expression->getExpression();
}
return $expression;
}
/**
* Returns a new expression object
*
* @return static
*/
public function createAggregationExpression(): self
{
return new static($this->dm, $this->class);
}
/**
* Converts a date object to a string according to a user-specified format.
*
* The format string can be any string literal, containing 0 or more format
* specifiers.
* The date argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/dateToString/
*
* @param mixed|self $expression
*/
public function dateToString(string $format, $expression): self
{
return $this->operator('$dateToString', ['format' => $format, 'date' => $expression]);
}
/**
* Returns the day of the month for a date as a number between 1 and 31.
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/dayOfMonth/
*
* @param mixed|self $expression
*/
public function dayOfMonth($expression): self
{
return $this->operator('$dayOfMonth', $expression);
}
/**
* Returns the day of the week for a date as a number between 1 (Sunday) and
* 7 (Saturday).
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/dayOfWeek/
*
* @param mixed|self $expression
*/
public function dayOfWeek($expression): self
{
return $this->operator('$dayOfWeek', $expression);
}
/**
* Returns the day of the year for a date as a number between 1 and 366.
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/dayOfYear/
*
* @param mixed|self $expression
*/
public function dayOfYear($expression): self
{
return $this->operator('$dayOfYear', $expression);
}
/**
* Adds a default statement for the current $switch operator.
*
* Requires {@link switch()} to be called first. The argument can be any
* valid expression.
*
* Note: if no default is specified and no branch evaluates to true, the
* $switch operator throws an error.
*
* @param mixed|self $expression
*/
public function default($expression): self
{
$this->requiresSwitchStatement(static::class . '::default');
if ($this->currentField) {
$this->expr[$this->currentField]['$switch']['default'] = $this->ensureArray($expression);
} else {
$this->expr['$switch']['default'] = $this->ensureArray($expression);
}
return $this;
}
/**
* Divides one number by another and returns the result. The first argument
* is divided by the second argument.
*
* The arguments can be any valid expression as long as the resolve to numbers.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/divide/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function divide($expression1, $expression2): self
{
return $this->operator('$divide', [$expression1, $expression2]);
}
/**
* Compares two values and returns whether the are equivalent.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/eq/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function eq($expression1, $expression2): self
{
return $this->operator('$eq', [$expression1, $expression2]);
}
/**
* Raises Euler’s number to the specified exponent and returns the result.
*
* The <exponent> expression can be any valid expression as long as it
* resolves to a number.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/exp/
*
* @param mixed|self $exponent
*/
public function exp($exponent): self
{
return $this->operator('$exp', $exponent);
}
/**
* Returns a new expression object
*
* @deprecated use createExpr instead
*/
public function expr(): self
{
trigger_deprecation(
'doctrine/mongodb-odm',
'2.3',
'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.',
__METHOD__,
static::class
);
return $this->createAggregationExpression();
}
/**
* Allows any expression to be used as a field value.
*
* @see https://docs.mongodb.com/manual/meta/aggregation-quick-reference/#aggregation-expressions
*
* @param mixed|self $value
*/
public function expression($value): self
{
$this->requiresCurrentField(__METHOD__);
$this->expr[$this->currentField] = $this->ensureArray($value);
return $this;
}
/**
* Set the current field for building the expression.
*/
public function field(string $fieldName): self
{
$fieldName = $this->getDocumentPersister()->prepareFieldName($fieldName);
$this->currentField = $fieldName;
return $this;
}
/**
* Selects a subset of the array to return based on the specified condition.
*
* Returns an array with only those elements that match the condition. The
* returned elements are in the original order.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/filter/
*
* @param mixed|self $input
* @param mixed|self $as
* @param mixed|self $cond
*/
public function filter($input, $as, $cond): self
{
return $this->operator('$filter', ['input' => $input, 'as' => $as, 'cond' => $cond]);
}
/**
* Returns the value that results from applying an expression to the first
* document in a group of documents that share the same group by key. Only
* meaningful when documents are in a defined order.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/first/
*
* @param mixed|self $expression
*/
public function first($expression): self
{
return $this->operator('$first', $expression);
}
/**
* Returns the largest integer less than or equal to the specified number.
*
* The <number> expression can be any valid expression as long as it
* resolves to a number.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/floor/
*
* @param mixed|self $number
*/
public function floor($number): self
{
return $this->operator('$floor', $number);
}
public function getExpression(): array
{
return $this->expr;
}
/**
* Compares two values and returns:
* true when the first value is greater than the second value.
* false when the first value is less than or equivalent to the second
* value.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/gt/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function gt($expression1, $expression2): self
{
return $this->operator('$gt', [$expression1, $expression2]);
}
/**
* Compares two values and returns:
* true when the first value is greater than or equivalent to the second
* value.
* false when the first value is less than the second value.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/gte/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function gte($expression1, $expression2): self
{
return $this->operator('$gte', [$expression1, $expression2]);
}
/**
* Returns the hour portion of a date as a number between 0 and 23.
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/hour/
*
* @param mixed|self $expression
*/
public function hour($expression): self
{
return $this->operator('$hour', $expression);
}
/**
* Evaluates an expression and returns the value of the expression if the
* expression evaluates to a non-null value. If the expression evaluates to
* a null value, including instances of undefined values or missing fields,
* returns the value of the replacement expression.
*
* The arguments can be any valid expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/
*
* @param mixed|self $expression
* @param mixed|self $replacementExpression
*/
public function ifNull($expression, $replacementExpression): self
{
return $this->operator('$ifNull', [$expression, $replacementExpression]);
}
/**
* Returns a boolean indicating whether a specified value is in an array.
*
* Unlike the $in query operator, the aggregation $in operator does not
* support matching by regular expressions.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/in/
*
* @param mixed|self $expression
* @param mixed|self $arrayExpression
*/
public function in($expression, $arrayExpression): self
{
return $this->operator('$in', [$expression, $arrayExpression]);
}
/**
* Searches an array for an occurrence of a specified value and returns the
* array index (zero-based) of the first occurrence. If the value is not
* found, returns -1.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfArray/
*
* @param mixed|self $arrayExpression Can be any valid expression as long as it resolves to an array.
* @param mixed|self $searchExpression Can be any valid expression.
* @param mixed|self $start Optional. An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
* @param mixed|self $end An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number.
*/
public function indexOfArray($arrayExpression, $searchExpression, $start = null, $end = null): self
{
$args = [$arrayExpression, $searchExpression];
if ($start !== null) {
$args[] = $start;
if ($end !== null) {
$args[] = $end;
}
}
return $this->operator('$indexOfArray', $args);
}
/**
* Searches a string for an occurrence of a substring and returns the UTF-8
* byte index (zero-based) of the first occurrence. If the substring is not
* found, returns -1.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfBytes/
*
* @param mixed|self $stringExpression Can be any valid expression as long as it resolves to a string.
* @param mixed|self $substringExpression Can be any valid expression as long as it resolves to a string.
* @param string|int|null $start An integral number that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
* @param string|int|null $end An integral number that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number.
*/
public function indexOfBytes($stringExpression, $substringExpression, $start = null, $end = null): self
{
$args = [$stringExpression, $substringExpression];
if ($start !== null) {
$args[] = $start;
if ($end !== null) {
$args[] = $end;
}
}
return $this->operator('$indexOfBytes', $args);
}
/**
* Searches a string for an occurrence of a substring and returns the UTF-8
* code point index (zero-based) of the first occurrence. If the substring is
* not found, returns -1.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfCP/
*
* @param mixed|self $stringExpression Can be any valid expression as long as it resolves to a string.
* @param mixed|self $substringExpression Can be any valid expression as long as it resolves to a string.
* @param string|int|null $start An integral number that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
* @param string|int|null $end An integral number that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number.
*/
public function indexOfCP($stringExpression, $substringExpression, $start = null, $end = null): self
{
$args = [$stringExpression, $substringExpression];
if ($start !== null) {
$args[] = $start;
if ($end !== null) {
$args[] = $end;
}
}
return $this->operator('$indexOfCP', $args);
}
/**
* Determines if the operand is an array. Returns a boolean.
*
* The <expression> can be any valid expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/isArray/
*
* @param mixed|self $expression
*/
public function isArray($expression): self
{
return $this->operator('$isArray', $expression);
}
/**
* Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday)
* to 7 (for Sunday).
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/isoDayOfWeek/
*
* @param mixed|self $expression
*/
public function isoDayOfWeek($expression): self
{
return $this->operator('$isoDayOfWeek', $expression);
}
/**
* Returns the week number in ISO 8601 format, ranging from 1 to 53.
*
* Week numbers start at 1 with the week (Monday through Sunday) that
* contains the year’s first Thursday.
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/isoWeek/
*
* @param mixed|self $expression
*/
public function isoWeek($expression): self
{
return $this->operator('$isoWeek', $expression);
}
/**
* Returns the year number in ISO 8601 format.
*
* The year starts with the Monday of week 1 (ISO 8601) and ends with the
* Sunday of the last week (ISO 8601).
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/isoWeek/
*
* @param mixed|self $expression
*/
public function isoWeekYear($expression): self
{
return $this->operator('$isoWeekYear', $expression);
}
/**
* Returns the value that results from applying an expression to the last
* document in a group of documents that share the same group by a field.
* Only meaningful when documents are in a defined order.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/last/
*
* @param mixed|self $expression
*/
public function last($expression): self
{
return $this->operator('$last', $expression);
}
/**
* Binds variables for use in the specified expression, and returns the
* result of the expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/let/
*
* @param mixed|self $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value.
* @param mixed|self $in The expression to evaluate.
*/
public function let($vars, $in): self
{
return $this->operator('$let', ['vars' => $vars, 'in' => $in]);
}
/**
* Returns a value without parsing. Use for values that the aggregation
* pipeline may interpret as an expression.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/literal/
*
* @param mixed|self $value
*/
public function literal($value): self
{
return $this->operator('$literal', $value);
}
/**
* Calculates the natural logarithm ln (i.e loge) of a number and returns
* the result as a double.
*
* The <number> expression can be any valid expression as long as it
* resolves to a non-negative number.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/log/
*
* @param mixed|self $number
*/
public function ln($number): self
{
return $this->operator('$ln', $number);
}
/**
* Calculates the log of a number in the specified base and returns the
* result as a double.
*
* The <number> expression can be any valid expression as long as it
* resolves to a non-negative number.
* The <base> expression can be any valid expression as long as it resolves
* to a positive number greater than 1.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/log/
*
* @param mixed|self $number
* @param mixed|self $base
*/
public function log($number, $base): self
{
return $this->operator('$log', [$number, $base]);
}
/**
* Calculates the log base 10 of a number and returns the result as a double.
*
* The <number> expression can be any valid expression as long as it
* resolves to a non-negative number.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/log10/
*
* @param mixed|self $number
*/
public function log10($number): self
{
return $this->operator('$log10', $number);
}
/**
* Compares two values and returns:
* true when the first value is less than the second value.
* false when the first value is greater than or equivalent to the second
* value.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/lt/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function lt($expression1, $expression2): self
{
return $this->operator('$lt', [$expression1, $expression2]);
}
/**
* Compares two values and returns:
* true when the first value is less than or equivalent to the second value.
* false when the first value is greater than the second value.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/lte/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function lte($expression1, $expression2): self
{
return $this->operator('$lte', [$expression1, $expression2]);
}
/**
* Applies an expression to each item in an array and returns an array with
* the applied results.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/map/
*
* @param mixed|self $input An expression that resolves to an array.
* @param string $as The variable name for the items in the input array. The in expression accesses each item in the input array by this variable.
* @param mixed|self $in The expression to apply to each item in the input array. The expression accesses the item by its variable name.
*/
public function map($input, $as, $in): self
{
return $this->operator('$map', ['input' => $input, 'as' => $as, 'in' => $in]);
}
/**
* Returns the highest value that results from applying an expression to
* each document in a group of documents that share the same group by key.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/max/
*
* @param mixed|self $expression
*/
public function max($expression): self
{
return $this->operator('$max', $expression);
}
/**
* Returns the metadata associated with a document in a pipeline operations.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/meta/
*
* @param mixed|self $metaDataKeyword
*/
public function meta($metaDataKeyword): self
{
return $this->operator('$meta', $metaDataKeyword);
}
/**
* Returns the millisecond portion of a date as an integer between 0 and 999.
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/millisecond/
*
* @param mixed|self $expression
*/
public function millisecond($expression): self
{
return $this->operator('$millisecond', $expression);
}
/**
* Returns the lowest value that results from applying an expression to each
* document in a group of documents that share the same group by key.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/min/
*
* @param mixed|self $expression
*/
public function min($expression): self
{
return $this->operator('$min', $expression);
}
/**
* Returns the minute portion of a date as a number between 0 and 59.
*
* The argument can be any expression as long as it resolves to a date.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/minute/
*
* @param mixed|self $expression
*/
public function minute($expression): self
{
return $this->operator('$minute', $expression);
}
/**
* Divides one number by another and returns the remainder. The first
* argument is divided by the second argument.
*
* The arguments can be any valid expression as long as they resolve to numbers.
*
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/mod/
*
* @param mixed|self $expression1
* @param mixed|self $expression2
*/
public function mod($expression1, $expression2): self