-
-
Notifications
You must be signed in to change notification settings - Fork 506
/
Copy pathBuilder.php
1648 lines (1411 loc) · 42.9 KB
/
Builder.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\Query;
use BadMethodCallException;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use GeoJson\Geometry\Geometry;
use GeoJson\Geometry\Point;
use InvalidArgumentException;
use MongoDB\BSON\Binary;
use MongoDB\BSON\Javascript;
use MongoDB\Collection;
use MongoDB\Driver\ReadPreference;
use function array_filter;
use function array_key_exists;
use function count;
use function func_get_args;
use function in_array;
use function is_array;
use function is_bool;
use function is_callable;
use function is_string;
use function strtolower;
/**
* Query builder for ODM.
*/
class Builder
{
/**
* The DocumentManager instance for this query
*
* @var DocumentManager
*/
private $dm;
/**
* The ClassMetadata instance.
*
* @var ClassMetadata
*/
private $class;
/**
* The current field we are operating on.
*
* @todo Change this to private once ODM requires doctrine/mongodb 1.1+
* @var string
*/
protected $currentField;
/**
* Whether or not to hydrate the data to documents.
*
* @var bool
*/
private $hydrate = true;
/**
* Whether or not to refresh the data for documents that are already in the identity map.
*
* @var bool
*/
private $refresh = false;
/**
* Array of primer Closure instances.
*
* @var array
*/
private $primers = [];
/**
* Whether or not to register documents in UnitOfWork.
*
* @var bool
*/
private $readOnly = false;
/** @var bool */
private $rewindable = true;
/**
* The Collection instance.
*
* @var Collection
*/
private $collection;
/**
* Array containing the query data.
*
* @var array
*/
private $query = ['type' => Query::TYPE_FIND];
/**
* The Expr instance used for building this query.
*
* This object includes the query criteria and the "new object" used for
* insert and update queries.
*
* @var Expr $expr
*/
private $expr;
/**
* Construct a Builder
*
* @param string[]|string|null $documentName (optional) an array of document names, the document name, or none
*/
public function __construct(DocumentManager $dm, $documentName = null)
{
$this->dm = $dm;
$this->expr = new Expr($dm);
if ($documentName === null) {
return;
}
$this->setDocumentName($documentName);
}
public function __clone()
{
$this->expr = clone $this->expr;
}
/**
* Add one or more $and clauses to the current query.
*
* You can create a new expression using the {@link Builder::expr()} method.
*
* @see Expr::addAnd()
* @see https://docs.mongodb.com/manual/reference/operator/and/
*
* @param array|Expr $expression
* @param array|Expr ...$expressions
*/
public function addAnd($expression, ...$expressions): self
{
$this->expr->addAnd(...func_get_args());
return $this;
}
/**
* Add one or more $nor clauses to the current query.
*
* You can create a new expression using the {@link Builder::expr()} method.
*
* @see Expr::addNor()
* @see https://docs.mongodb.com/manual/reference/operator/nor/
*
* @param array|Expr $expression
* @param array|Expr ...$expressions
*/
public function addNor($expression, ...$expressions): self
{
$this->expr->addNor(...func_get_args());
return $this;
}
/**
* Add one or more $or clauses to the current query.
*
* You can create a new expression using the {@link Builder::expr()} method.
*
* @see Expr::addOr()
* @see https://docs.mongodb.com/manual/reference/operator/or/
*
* @param array|Expr $expression
* @param array|Expr ...$expressions
*/
public function addOr($expression, ...$expressions): self
{
$this->expr->addOr(...func_get_args());
return $this;
}
/**
* Append one or more values to the current array field only if they do not
* already exist in the array.
*
* If the field does not exist, it will be set to an array containing the
* unique value(s) in the argument. If the field is not an array, the query
* will yield an error.
*
* Multiple values may be specified by provided an Expr object and using
* {@link Expr::each()}.
*
* @see Expr::addToSet()
* @see https://docs.mongodb.com/manual/reference/operator/addToSet/
* @see https://docs.mongodb.com/manual/reference/operator/each/
*
* @param mixed|Expr $valueOrExpression
*/
public function addToSet($valueOrExpression): self
{
$this->expr->addToSet($valueOrExpression);
return $this;
}
/**
* Specify $all criteria for the current field.
*
* @see Expr::all()
* @see https://docs.mongodb.com/manual/reference/operator/all/
*/
public function all(array $values): self
{
$this->expr->all($values);
return $this;
}
/**
* Apply a bitwise and operation on the current field.
*
* @see Expr::bitAnd()
* @see https://docs.mongodb.com/manual/reference/operator/update/bit/
*
* @return $this
*/
public function bitAnd(int $value): self
{
$this->expr->bitAnd($value);
return $this;
}
/**
* Apply a bitwise or operation on the current field.
*
* @see Expr::bitOr()
* @see https://docs.mongodb.com/manual/reference/operator/update/bit/
*/
public function bitOr(int $value): self
{
$this->expr->bitOr($value);
return $this;
}
/**
* Matches documents where all of the bit positions given by the query are
* clear.
*
* @see Expr::bitsAllClear()
* @see https://docs.mongodb.com/manual/reference/operator/query/bitsAllClear/
*
* @param int|array|Binary $value
*/
public function bitsAllClear($value): self
{
$this->expr->bitsAllClear($value);
return $this;
}
/**
* Matches documents where all of the bit positions given by the query are
* set.
*
* @see Expr::bitsAllSet()
* @see https://docs.mongodb.com/manual/reference/operator/query/bitsAllSet/
*
* @param int|array|Binary $value
*/
public function bitsAllSet($value): self
{
$this->expr->bitsAllSet($value);
return $this;
}
/**
* Matches documents where any of the bit positions given by the query are
* clear.
*
* @see Expr::bitsAnyClear()
* @see https://docs.mongodb.com/manual/reference/operator/query/bitsAnyClear/
*
* @param int|array|Binary $value
*/
public function bitsAnyClear($value): self
{
$this->expr->bitsAnyClear($value);
return $this;
}
/**
* Matches documents where any of the bit positions given by the query are
* set.
*
* @see Expr::bitsAnySet()
* @see https://docs.mongodb.com/manual/reference/operator/query/bitsAnySet/
*
* @param int|array|Binary $value
*/
public function bitsAnySet($value): self
{
$this->expr->bitsAnySet($value);
return $this;
}
/**
* Apply a bitwise xor operation on the current field.
*
* @see Expr::bitXor()
* @see https://docs.mongodb.com/manual/reference/operator/update/bit/
*/
public function bitXor(int $value): self
{
$this->expr->bitXor($value);
return $this;
}
/**
* A boolean flag to enable or disable case sensitive search for $text
* criteria.
*
* This method must be called after text().
*
* @see Expr::caseSensitive()
* @see https://docs.mongodb.com/manual/reference/operator/query/text/
*
* @throws BadMethodCallException If the query does not already have $text criteria.
*/
public function caseSensitive(bool $caseSensitive): self
{
$this->expr->caseSensitive($caseSensitive);
return $this;
}
/**
* Associates a comment to any expression taking a query predicate.
*
* @see Expr::comment()
* @see https://docs.mongodb.com/manual/reference/operator/query/comment/
*/
public function comment(string $comment): self
{
$this->expr->comment($comment);
return $this;
}
/**
* Change the query type to count.
*/
public function count(): self
{
$this->query['type'] = Query::TYPE_COUNT;
return $this;
}
/**
* Sets the value of the current field to the current date, either as a date or a timestamp.
*
* @see Expr::currentDate()
* @see https://docs.mongodb.com/manual/reference/operator/update/currentDate/
*/
public function currentDate(string $type = 'date'): self
{
$this->expr->currentDate($type);
return $this;
}
/**
* Return an array of information about the Builder state for debugging.
*
* The $name parameter may be used to return a specific key from the
* internal $query array property. If omitted, the entire array will be
* returned.
*
* @return mixed
*/
public function debug(?string $name = null)
{
return $name !== null ? $this->query[$name] : $this->query;
}
/**
* A boolean flag to enable or disable diacritic sensitive search for $text
* criteria.
*
* This method must be called after text().
*
* @see Builder::diacriticSensitive()
* @see https://docs.mongodb.com/manual/reference/operator/query/text/
*
* @throws BadMethodCallException If the query does not already have $text criteria.
*/
public function diacriticSensitive(bool $diacriticSensitive): self
{
$this->expr->diacriticSensitive($diacriticSensitive);
return $this;
}
/**
* Change the query type to a distinct command.
*
* @see https://docs.mongodb.com/manual/reference/command/distinct/
*/
public function distinct(string $field): self
{
$this->query['type'] = Query::TYPE_DISTINCT;
$this->query['distinct'] = $field;
return $this;
}
/**
* Specify $elemMatch criteria for the current field.
*
* You can create a new expression using the {@link Builder::expr()} method.
*
* @see Expr::elemMatch()
* @see https://docs.mongodb.com/manual/reference/operator/elemMatch/
*
* @param array|Expr $expression
*/
public function elemMatch($expression): self
{
$this->expr->elemMatch($expression);
return $this;
}
/**
* Specify an equality match for the current field.
*
* @see Expr::equals()
*
* @param mixed $value
*/
public function equals($value): self
{
$this->expr->equals($value);
return $this;
}
/**
* Set one or more fields to be excluded from the query projection.
*
* If fields have been selected for inclusion, only the "_id" field may be
* excluded.
*
* @param array|string $fieldName,...
*/
public function exclude($fieldName = null): self
{
if (! isset($this->query['select'])) {
$this->query['select'] = [];
}
$fieldNames = is_array($fieldName) ? $fieldName : func_get_args();
foreach ($fieldNames as $fieldName) {
$this->query['select'][$fieldName] = 0;
}
return $this;
}
/**
* Specify $exists criteria for the current field.
*
* @see Expr::exists()
* @see https://docs.mongodb.com/manual/reference/operator/exists/
*/
public function exists(bool $bool): self
{
$this->expr->exists($bool);
return $this;
}
/**
* Create a new Expr instance that can be used as an expression with the Builder
*/
public function expr(): Expr
{
$expr = new Expr($this->dm);
$expr->setClassMetadata($this->class);
return $expr;
}
/**
* Set the current field to operate on.
*/
public function field(string $field): self
{
$this->currentField = $field;
$this->expr->field($field);
return $this;
}
/**
* Change the query type to find and optionally set and change the class being queried.
*/
public function find(?string $documentName = null): self
{
$this->setDocumentName($documentName);
$this->query['type'] = Query::TYPE_FIND;
return $this;
}
public function findAndRemove(?string $documentName = null): self
{
$this->setDocumentName($documentName);
$this->query['type'] = Query::TYPE_FIND_AND_REMOVE;
return $this;
}
public function findAndUpdate(?string $documentName = null): self
{
$this->setDocumentName($documentName);
$this->query['type'] = Query::TYPE_FIND_AND_UPDATE;
return $this;
}
/**
* Add $geoIntersects criteria with a GeoJSON geometry to the query.
*
* The geometry parameter GeoJSON object or an array corresponding to the
* geometry's JSON representation.
*
* @see Expr::geoIntersects()
* @see https://docs.mongodb.com/manual/reference/operator/geoIntersects/
*
* @param array|Geometry $geometry
*/
public function geoIntersects($geometry): self
{
$this->expr->geoIntersects($geometry);
return $this;
}
/**
* Add $geoWithin criteria with a GeoJSON geometry to the query.
*
* The geometry parameter GeoJSON object or an array corresponding to the
* geometry's JSON representation.
*
* @see Expr::geoWithin()
* @see https://docs.mongodb.com/manual/reference/operator/geoWithin/
*
* @param array|Geometry $geometry
*/
public function geoWithin($geometry): self
{
$this->expr->geoWithin($geometry);
return $this;
}
/**
* Add $geoWithin criteria with a $box shape to the query.
*
* A rectangular polygon will be constructed from a pair of coordinates
* corresponding to the bottom left and top right corners.
*
* Note: the $box operator only supports legacy coordinate pairs and 2d
* indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
*
* @see Expr::geoWithinBox()
* @see https://docs.mongodb.com/manual/reference/operator/box/
*/
public function geoWithinBox(float $x1, float $y1, float $x2, float $y2): self
{
$this->expr->geoWithinBox($x1, $y1, $x2, $y2);
return $this;
}
/**
* Add $geoWithin criteria with a $center shape to the query.
*
* Note: the $center operator only supports legacy coordinate pairs and 2d
* indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
*
* @see Expr::geoWithinCenter()
* @see https://docs.mongodb.com/manual/reference/operator/center/
*/
public function geoWithinCenter(float $x, float $y, float $radius): self
{
$this->expr->geoWithinCenter($x, $y, $radius);
return $this;
}
/**
* Add $geoWithin criteria with a $centerSphere shape to the query.
*
* Note: the $centerSphere operator supports both 2d and 2dsphere indexes.
*
* @see Expr::geoWithinCenterSphere()
* @see https://docs.mongodb.com/manual/reference/operator/centerSphere/
*/
public function geoWithinCenterSphere(float $x, float $y, float $radius): self
{
$this->expr->geoWithinCenterSphere($x, $y, $radius);
return $this;
}
/**
* Add $geoWithin criteria with a $polygon shape to the query.
*
* Point coordinates are in x, y order (easting, northing for projected
* coordinates, longitude, latitude for geographic coordinates).
*
* The last point coordinate is implicitly connected with the first.
*
* Note: the $polygon operator only supports legacy coordinate pairs and 2d
* indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
*
* @see Expr::geoWithinPolygon()
* @see https://docs.mongodb.com/manual/reference/operator/polygon/
*
* @param array $point1 First point of the polygon
* @param array $point2 Second point of the polygon
* @param array $point3 Third point of the polygon
* @param array ...$points Additional points of the polygon
*/
public function geoWithinPolygon($point1, $point2, $point3, ...$points): self
{
$this->expr->geoWithinPolygon(...func_get_args());
return $this;
}
/**
* Return the expression's "new object".
*
* @see Expr::getNewObj()
*/
public function getNewObj(): array
{
return $this->expr->getNewObj();
}
/**
* Gets the Query executable.
*/
public function getQuery(array $options = []): Query
{
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
$query = $this->query;
$query['query'] = $this->expr->getQuery();
$query['query'] = $documentPersister->addDiscriminatorToPreparedQuery($query['query']);
$query['query'] = $documentPersister->addFilterToPreparedQuery($query['query']);
$query['newObj'] = $this->expr->getNewObj();
if (isset($query['distinct'])) {
$query['distinct'] = $documentPersister->prepareFieldName($query['distinct']);
}
if (
$this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION && ! empty($query['upsert']) &&
(empty($query['query'][$this->class->discriminatorField]) || is_array($query['query'][$this->class->discriminatorField]))
) {
throw new InvalidArgumentException('Upsert query that is to be performed on discriminated document does not have single ' .
'discriminator. Either not use base class or set \'' . $this->class->discriminatorField . '\' field manually.');
}
if (! empty($query['select'])) {
$query['select'] = $documentPersister->prepareProjection($query['select']);
if (
$this->hydrate && $this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION
&& ! isset($query['select'][$this->class->discriminatorField])
) {
$includeMode = 0 < count(array_filter($query['select'], static function ($mode) {
return $mode === 1;
}));
if ($includeMode) {
$query['select'][$this->class->discriminatorField] = 1;
}
}
}
if (isset($query['sort'])) {
$query['sort'] = $documentPersister->prepareSort($query['sort']);
}
if ($this->class->readPreference && ! array_key_exists('readPreference', $query)) {
$query['readPreference'] = new ReadPreference($this->class->readPreference, $this->class->readPreferenceTags);
}
return new Query(
$this->dm,
$this->class,
$this->collection,
$query,
$options,
$this->hydrate,
$this->refresh,
$this->primers,
$this->readOnly,
$this->rewindable
);
}
/**
* Return the expression's query criteria.
*
* @see Expr::getQuery()
*/
public function getQueryArray(): array
{
return $this->expr->getQuery();
}
/**
* Get the type of this query.
*/
public function getType(): int
{
return $this->query['type'];
}
/**
* Specify $gt criteria for the current field.
*
* @see Expr::gt()
* @see https://docs.mongodb.com/manual/reference/operator/gt/
*
* @param mixed $value
*/
public function gt($value): self
{
$this->expr->gt($value);
return $this;
}
/**
* Specify $gte criteria for the current field.
*
* @see Expr::gte()
* @see https://docs.mongodb.com/manual/reference/operator/gte/
*
* @param mixed $value
*/
public function gte($value): self
{
$this->expr->gte($value);
return $this;
}
/**
* Set the index hint for the query.
*
* @param array|string $index
*/
public function hint($index): self
{
$this->query['hint'] = $index;
return $this;
}
public function hydrate(bool $bool = true): self
{
$this->hydrate = $bool;
return $this;
}
/**
* Set the immortal cursor flag.
*/
public function immortal(bool $bool = true): self
{
$this->query['immortal'] = $bool;
return $this;
}
/**
* Specify $in criteria for the current field.
*
* @see Expr::in()
* @see https://docs.mongodb.com/manual/reference/operator/in/
*/
public function in(array $values): self
{
$this->expr->in($values);
return $this;
}
/**
* Increment the current field.
*
* If the field does not exist, it will be set to this value.
*
* @see Expr::inc()
* @see https://docs.mongodb.com/manual/reference/operator/inc/
*
* @param float|int $value
*/
public function inc($value): self
{
$this->expr->inc($value);
return $this;
}
public function includesReferenceTo(object $document): self
{
$this->expr->includesReferenceTo($document);
return $this;
}
public function insert(?string $documentName = null): self
{
$this->setDocumentName($documentName);
$this->query['type'] = Query::TYPE_INSERT;
return $this;
}
/**
* Set the $language option for $text criteria.
*
* This method must be called after text().
*
* @see Expr::language()
* @see https://docs.mongodb.com/manual/reference/operator/query/text/
*/
public function language(string $language): self
{
$this->expr->language($language);
return $this;
}
/**
* Set the limit for the query.
*
* This is only relevant for find queries and count commands.
*
* @see Query::prepareCursor()
*/
public function limit(int $limit): self
{
$this->query['limit'] = $limit;
return $this;
}
/**
* Specify $lt criteria for the current field.
*
* @see Expr::lte()
* @see https://docs.mongodb.com/manual/reference/operator/lte/
*
* @param mixed $value
*/
public function lt($value): self
{
$this->expr->lt($value);
return $this;
}
/**
* Specify $lte criteria for the current field.
*
* @see Expr::lte()
* @see https://docs.mongodb.com/manual/reference/operator/lte/
*
* @param mixed $value
*/
public function lte($value): self
{
$this->expr->lte($value);
return $this;
}
/**
* Updates the value of the field to a specified value if the specified value is greater than the current value of the field.
*
* @see Expr::max()
* @see https://docs.mongodb.com/manual/reference/operator/update/max/
*
* @param mixed $value
*/
public function max($value): self
{
$this->expr->max($value);
return $this;
}
/**
* Specifies a cumulative time limit in milliseconds for processing operations on a cursor.
*/
public function maxTimeMS(int $ms): self
{
$this->query['maxTimeMS'] = $ms;
return $this;
}
/**
* Updates the value of the field to a specified value if the specified value is less than the current value of the field.
*
* @see Expr::min()
* @see https://docs.mongodb.com/manual/reference/operator/update/min/
*
* @param mixed $value
*/
public function min($value): self
{
$this->expr->min($value);
return $this;
}
/**
* Specify $mod criteria for the current field.
*
* @see Expr::mod()
* @see https://docs.mongodb.com/manual/reference/operator/mod/
*
* @param float|int $divisor
* @param float|int $remainder
*/
public function mod($divisor, $remainder = 0): self
{
$this->expr->mod($divisor, $remainder);
return $this;
}
/**
* Multiply the current field.
*
* If the field does not exist, it will be set to 0.
*
* @see Expr::mul()
* @see https://docs.mongodb.com/manual/reference/operator/update/mul/
*
* @param float|int $value
*/
public function mul($value): self
{
$this->expr->mul($value);
return $this;
}
/**
* Add $near criteria to the query.
*
* A GeoJSON point may be provided as the first and only argument for
* 2dsphere queries. This single parameter may be a GeoJSON point object or
* an array corresponding to the point's JSON representation.
*
* @see Expr::near()
* @see https://docs.mongodb.com/manual/reference/operator/near/
*
* @param float|array|Point $x
* @param float $y
*/
public function near($x, $y = null): self
{
$this->expr->near($x, $y);
return $this;