1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\ODM\MongoDB\Aggregation; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata; |
6
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
7
|
|
|
use Doctrine\ODM\MongoDB\Types\Type; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Fluent interface for building aggregation pipelines. |
11
|
|
|
*/ |
12
|
|
|
class Expr |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var DocumentManager |
16
|
|
|
*/ |
17
|
|
|
private $dm; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ClassMetadata |
21
|
|
|
*/ |
22
|
|
|
private $class; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $expr = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The current field we are operating on. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $currentField; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
private $switchBranch; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
*/ |
44
|
367 |
|
public function __construct(DocumentManager $dm, ClassMetadata $class) |
45
|
|
|
{ |
46
|
367 |
|
$this->dm = $dm; |
47
|
367 |
|
$this->class = $class; |
48
|
367 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the absolute value of a number. |
52
|
|
|
* |
53
|
|
|
* The <number> argument can be any valid expression as long as it resolves |
54
|
|
|
* to a number. |
55
|
10 |
|
* |
56
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/abs/ |
57
|
10 |
|
* @param mixed|self $number |
58
|
10 |
|
* @return $this |
59
|
|
|
* |
60
|
|
|
* @since 1.3 |
61
|
|
|
*/ |
62
|
10 |
|
public function abs($number) |
63
|
|
|
{ |
64
|
|
|
return $this->operator('$abs', $number); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Adds numbers together or adds numbers and a date. If one of the arguments |
69
|
|
|
* is a date, $add treats the other arguments as milliseconds to add to the |
70
|
|
|
* date. |
71
|
|
|
* |
72
|
|
|
* The arguments can be any valid expression as long as they resolve to |
73
|
|
|
* either all numbers or to numbers and a date. |
74
|
|
|
* |
75
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/add/ |
76
|
|
|
* @param mixed|self $expression1 |
77
|
3 |
|
* @param mixed|self $expression2 |
78
|
|
|
* @param mixed|self $expression3,... Additional expressions |
|
|
|
|
79
|
3 |
|
* @return $this |
80
|
|
|
*/ |
81
|
|
|
public function add($expression1, $expression2 /* , $expression3, ... */) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
return $this->operator('$add', func_get_args()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Adds one or more $and clauses to the current expression. |
88
|
|
|
* |
89
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/and/ |
90
|
|
|
* @param array|self $expression |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function addAnd($expression /*, $expression2, ... */) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
if (! isset($this->expr['$and'])) { |
96
|
15 |
|
$this->expr['$and'] = []; |
97
|
|
|
} |
98
|
15 |
|
|
99
|
|
|
$this->expr['$and'] = array_merge($this->expr['$and'], array_map([$this, 'ensureArray'], func_get_args())); |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Adds one or more $or clause to the current expression. |
106
|
|
|
* |
107
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/or/ |
108
|
1 |
|
* @param array|self $expression |
109
|
|
|
* @return $this |
110
|
1 |
|
*/ |
111
|
1 |
View Code Duplication |
public function addOr($expression /*, $expression2, ... */) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
if (! isset($this->expr['$or'])) { |
114
|
1 |
|
$this->expr['$or'] = []; |
115
|
|
|
} |
116
|
1 |
|
|
117
|
|
|
$this->expr['$or'] = array_merge($this->expr['$or'], array_map([$this, 'ensureArray'], func_get_args())); |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns an array of all unique values that results from applying an |
124
|
|
|
* expression to each document in a group of documents that share the same |
125
|
|
|
* group by key. Order of the elements in the output array is unspecified. |
126
|
|
|
* |
127
|
|
|
* AddToSet is an accumulator operation only available in the group stage. |
128
|
|
|
* |
129
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/addToSet/ |
130
|
|
|
* @param mixed|self $expression |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
|
|
public function addToSet($expression) |
134
|
|
|
{ |
135
|
|
|
return $this->operator('$addToSet', $expression); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Evaluates an array as a set and returns true if no element in the array |
140
|
|
|
* is false. Otherwise, returns false. An empty array returns true. |
141
|
|
|
* |
142
|
|
|
* The expression must resolve to an array. |
143
|
|
|
* |
144
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/allElementsTrue/ |
145
|
|
|
* @param mixed|self $expression |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
2 |
|
public function allElementsTrue($expression) |
149
|
|
|
{ |
150
|
2 |
|
return $this->operator('$allElementsTrue', $expression); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Evaluates an array as a set and returns true if any of the elements are |
155
|
|
|
* true and false otherwise. An empty array returns false. |
156
|
|
|
* |
157
|
|
|
* The expression must resolve to an array. |
158
|
|
|
* |
159
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/anyElementTrue/ |
160
|
|
|
* @param array|self $expression |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
3 |
|
public function anyElementTrue($expression) |
164
|
|
|
{ |
165
|
3 |
|
return $this->operator('$anyElementTrue', $expression); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns the element at the specified array index. |
170
|
|
|
* |
171
|
|
|
* The <array> expression can be any valid expression as long as it resolves |
172
|
|
|
* to an array. |
173
|
|
|
* The <idx> expression can be any valid expression as long as it resolves |
174
|
|
|
* to an integer. |
175
|
|
|
* |
176
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/arrayElemAt/ |
177
|
|
|
* @param mixed|self $array |
178
|
3 |
|
* @param mixed|self $index |
179
|
|
|
* @return $this |
180
|
3 |
|
* |
181
|
|
|
* @since 1.3 |
182
|
|
|
*/ |
183
|
|
|
public function arrayElemAt($array, $index) |
184
|
|
|
{ |
185
|
|
|
return $this->operator('$arrayElemAt', [$array, $index]); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Returns the average value of the numeric values that result from applying |
190
|
|
|
* a specified expression to each document in a group of documents that |
191
|
|
|
* share the same group by key. Ignores nun-numeric values. |
192
|
|
|
* |
193
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/ |
194
|
|
|
* @param mixed|self $expression |
195
|
|
|
* @return $this |
196
|
|
|
*/ |
197
|
|
|
public function avg($expression) |
198
|
3 |
|
{ |
199
|
|
|
return $this->operator('$avg', $expression); |
200
|
3 |
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Adds a case statement for a branch of the $switch operator. |
204
|
|
|
* |
205
|
|
|
* Requires {@link switch()} to be called first. The argument can be any |
206
|
|
|
* valid expression that resolves to a boolean. If the result is not a |
207
|
|
|
* boolean, it is coerced to a boolean value. |
208
|
|
|
* |
209
|
|
|
* @param mixed|self $expression |
210
|
|
|
* |
211
|
|
|
* @return $this |
212
|
10 |
|
*/ |
213
|
|
|
public function case($expression) |
214
|
10 |
|
{ |
215
|
|
|
$this->requiresSwitchStatement(static::class . '::case'); |
216
|
|
|
|
217
|
|
|
$this->switchBranch = ['case' => $expression]; |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Returns the smallest integer greater than or equal to the specified number. |
224
|
|
|
* |
225
|
|
|
* The <number> expression can be any valid expression as long as it |
226
|
|
|
* resolves to a number. |
227
|
|
|
* |
228
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/ceil/ |
229
|
|
|
* @param mixed|self $number |
230
|
6 |
|
* @return $this |
231
|
|
|
* |
232
|
6 |
|
* @since 1.3 |
233
|
|
|
*/ |
234
|
4 |
|
public function ceil($number) |
235
|
|
|
{ |
236
|
4 |
|
return $this->operator('$ceil', $number); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Compares two values and returns: |
241
|
|
|
* -1 if the first value is less than the second. |
242
|
|
|
* 1 if the first value is greater than the second. |
243
|
|
|
* 0 if the two values are equivalent. |
244
|
|
|
* |
245
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/cmp/ |
246
|
|
|
* @param mixed|self $expression1 |
247
|
|
|
* @param mixed|self $expression2 |
248
|
|
|
* @return $this |
249
|
|
|
*/ |
250
|
|
|
public function cmp($expression1, $expression2) |
251
|
3 |
|
{ |
252
|
|
|
return $this->operator('$cmp', [$expression1, $expression2]); |
253
|
3 |
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Concatenates strings and returns the concatenated string. |
257
|
|
|
* |
258
|
|
|
* The arguments can be any valid expression as long as they resolve to |
259
|
|
|
* strings. If the argument resolves to a value of null or refers to a field |
260
|
|
|
* that is missing, $concat returns null. |
261
|
|
|
* |
262
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/concat/ |
263
|
|
|
* @param mixed|self $expression1 |
264
|
|
|
* @param mixed|self $expression2 |
265
|
|
|
* @param mixed|self $expression3,... Additional expressions |
|
|
|
|
266
|
|
|
* @return $this |
267
|
3 |
|
*/ |
268
|
|
|
public function concat($expression1, $expression2 /* , $expression3, ... */) |
|
|
|
|
269
|
3 |
|
{ |
270
|
|
|
return $this->operator('$concat', func_get_args()); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Concatenates arrays to return the concatenated array. |
275
|
|
|
* |
276
|
|
|
* The <array> expressions can be any valid expression as long as they |
277
|
|
|
* resolve to an array. |
278
|
|
|
* |
279
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/concatArrays/ |
280
|
|
|
* @param mixed|self $array1 |
281
|
|
|
* @param mixed|self $array2 |
282
|
|
|
* @param mixed|self $array3, ... Additional expressions |
|
|
|
|
283
|
|
|
* @return $this |
284
|
|
|
* |
285
|
9 |
|
* @since 1.3 |
286
|
|
|
*/ |
287
|
9 |
|
public function concatArrays($array1, $array2 /* , $array3, ... */) |
|
|
|
|
288
|
|
|
{ |
289
|
|
|
return $this->operator('$concatArrays', func_get_args()); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Evaluates a boolean expression to return one of the two specified return |
294
|
|
|
* expressions. |
295
|
|
|
* |
296
|
|
|
* The arguments can be any valid expression. |
297
|
|
|
* |
298
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/cond/ |
299
|
|
|
* @param mixed|self $if |
300
|
|
|
* @param mixed|self $then |
301
|
|
|
* @param mixed|self $else |
302
|
|
|
* @return $this |
303
|
|
|
*/ |
304
|
6 |
|
public function cond($if, $then, $else) |
305
|
|
|
{ |
306
|
6 |
|
return $this->operator('$cond', ['if' => $if, 'then' => $then, 'else' => $else]); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Converts an expression object into an array, recursing into nested items |
311
|
|
|
* |
312
|
|
|
* For expression objects, it calls getExpression on the expression object. |
313
|
|
|
* For arrays, it recursively calls itself for each array item. Other values |
314
|
|
|
* are returned directly. |
315
|
|
|
* |
316
|
|
|
* @param mixed|self $expression |
317
|
|
|
* @return string|array |
318
|
|
|
* @internal |
319
|
|
|
*/ |
320
|
|
|
public static function convertExpression($expression) |
321
|
10 |
|
{ |
322
|
|
|
if (is_array($expression)) { |
323
|
10 |
|
return array_map(['static', 'convertExpression'], $expression); |
324
|
|
|
} elseif ($expression instanceof self) { |
325
|
|
|
return $expression->getExpression(); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
return $expression; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Converts a date object to a string according to a user-specified format. |
333
|
|
|
* |
334
|
|
|
* The format string can be any string literal, containing 0 or more format |
335
|
|
|
* specifiers. |
336
|
|
|
* The date argument can be any expression as long as it resolves to a date. |
337
|
1 |
|
* |
338
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/dateToString/ |
339
|
1 |
|
* @param string $format |
340
|
|
|
* @param mixed|self $expression |
341
|
1 |
|
* @return $this |
342
|
1 |
|
*/ |
343
|
|
|
public function dateToString($format, $expression) |
344
|
|
|
{ |
345
|
|
|
return $this->operator('$dateToString', ['format' => $format, 'date' => $expression]); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Returns the day of the month for a date as a number between 1 and 31. |
350
|
|
|
* |
351
|
|
|
* The argument can be any expression as long as it resolves to a date. |
352
|
|
|
* |
353
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/dayOfMonth/ |
354
|
|
|
* @param mixed|self $expression |
355
|
|
|
* @return $this |
356
|
|
|
*/ |
357
|
|
|
public function dayOfMonth($expression) |
358
|
|
|
{ |
359
|
|
|
return $this->operator('$dayOfMonth', $expression); |
360
|
3 |
|
} |
361
|
|
|
|
362
|
3 |
|
/** |
363
|
|
|
* Returns the day of the week for a date as a number between 1 (Sunday) and |
364
|
|
|
* 7 (Saturday). |
365
|
|
|
* |
366
|
|
|
* The argument can be any expression as long as it resolves to a date. |
367
|
|
|
* |
368
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/dayOfWeek/ |
369
|
|
|
* @param mixed|self $expression |
370
|
|
|
* @return $this |
371
|
|
|
*/ |
372
|
|
|
public function dayOfWeek($expression) |
373
|
|
|
{ |
374
|
7 |
|
return $this->operator('$dayOfWeek', $expression); |
375
|
|
|
} |
376
|
7 |
|
|
377
|
|
|
/** |
378
|
|
|
* Returns the day of the year for a date as a number between 1 and 366. |
379
|
|
|
* |
380
|
|
|
* The argument can be any expression as long as it resolves to a date. |
381
|
|
|
* |
382
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/dayOfYear/ |
383
|
|
|
* @param mixed|self $expression |
384
|
|
|
* @return $this |
385
|
|
|
*/ |
386
|
|
|
public function dayOfYear($expression) |
387
|
|
|
{ |
388
|
|
|
return $this->operator('$dayOfYear', $expression); |
389
|
7 |
|
} |
390
|
|
|
|
391
|
7 |
|
/** |
392
|
|
|
* Adds a default statement for the current $switch operator. |
393
|
|
|
* |
394
|
|
|
* Requires {@link switch()} to be called first. The argument can be any |
395
|
|
|
* valid expression. |
396
|
|
|
* |
397
|
|
|
* Note: if no default is specified and no branch evaluates to true, the |
398
|
|
|
* $switch operator throws an error. |
399
|
|
|
* |
400
|
|
|
* @param mixed|self $expression |
401
|
|
|
* |
402
|
|
|
* @return $this |
403
|
3 |
|
*/ |
404
|
|
|
public function default($expression) |
405
|
3 |
|
{ |
406
|
|
|
$this->requiresSwitchStatement(static::class . '::default'); |
407
|
|
|
|
408
|
|
|
if ($this->currentField) { |
409
|
|
|
$this->expr[$this->currentField]['$switch']['default'] = $this->ensureArray($expression); |
410
|
|
|
} else { |
411
|
|
|
$this->expr['$switch']['default'] = $this->ensureArray($expression); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
return $this; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Divides one number by another and returns the result. The first argument |
419
|
|
|
* is divided by the second argument. |
420
|
|
|
* |
421
|
|
|
* The arguments can be any valid expression as long as the resolve to numbers. |
422
|
|
|
* |
423
|
4 |
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/divide/ |
424
|
|
|
* @param mixed|self $expression1 |
425
|
4 |
|
* @param mixed|self $expression2 |
426
|
|
|
* @return $this |
427
|
2 |
|
*/ |
428
|
|
|
public function divide($expression1, $expression2) |
429
|
|
|
{ |
430
|
2 |
|
return $this->operator('$divide', [$expression1, $expression2]); |
431
|
|
|
} |
432
|
|
|
|
433
|
2 |
|
/** |
434
|
|
|
* Compares two values and returns whether the are equivalent. |
435
|
|
|
* |
436
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/eq/ |
437
|
|
|
* @param mixed|self $expression1 |
438
|
|
|
* @param mixed|self $expression2 |
439
|
|
|
* @return $this |
440
|
|
|
*/ |
441
|
|
|
public function eq($expression1, $expression2) |
442
|
|
|
{ |
443
|
|
|
return $this->operator('$eq', [$expression1, $expression2]); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
3 |
|
* Raises Euler’s number to the specified exponent and returns the result. |
448
|
|
|
* |
449
|
3 |
|
* The <exponent> expression can be any valid expression as long as it |
450
|
|
|
* resolves to a number. |
451
|
|
|
* |
452
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/exp/ |
453
|
|
|
* @param mixed|self $exponent |
454
|
|
|
* @return $this |
455
|
|
|
* |
456
|
|
|
* @since 1.3 |
457
|
|
|
*/ |
458
|
|
|
public function exp($exponent) |
459
|
|
|
{ |
460
|
9 |
|
return $this->operator('$exp', $exponent); |
461
|
|
|
} |
462
|
9 |
|
|
463
|
|
|
/** |
464
|
|
|
* Returns a new expression object |
465
|
|
|
* |
466
|
|
|
* @return static |
467
|
|
|
* |
468
|
|
|
* @since 1.3 |
469
|
|
|
*/ |
470
|
|
|
public function expr() |
471
|
|
|
{ |
472
|
|
|
return new static($this->dm, $this->class); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Allows any expression to be used as a field value. |
477
|
3 |
|
* |
478
|
|
|
* @see http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#aggregation-expressions |
479
|
3 |
|
* @param mixed|self $value |
480
|
|
|
* @return $this |
481
|
|
|
*/ |
482
|
|
|
public function expression($value) |
483
|
|
|
{ |
484
|
|
|
$this->requiresCurrentField(__METHOD__); |
485
|
|
|
$this->expr[$this->currentField] = $this->ensureArray($value); |
486
|
|
|
|
487
|
|
|
return $this; |
488
|
|
|
} |
489
|
4 |
|
|
490
|
|
|
/** |
491
|
4 |
|
* Set the current field for building the expression. |
492
|
|
|
* |
493
|
|
|
* @param string $fieldName |
494
|
|
|
* @return $this |
495
|
|
|
*/ |
496
|
|
|
public function field($fieldName) |
497
|
|
|
{ |
498
|
|
|
$fieldName = $this->getDocumentPersister()->prepareFieldName($fieldName); |
499
|
|
|
$this->currentField = (string) $fieldName; |
500
|
|
|
|
501
|
12 |
|
return $this; |
502
|
|
|
} |
503
|
12 |
|
|
504
|
11 |
|
/** |
505
|
|
|
* Selects a subset of the array to return based on the specified condition. |
506
|
11 |
|
* |
507
|
|
|
* Returns an array with only those elements that match the condition. The |
508
|
|
|
* returned elements are in the original order. |
509
|
|
|
* |
510
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/filter/ |
511
|
|
|
* @param mixed|self $input |
512
|
|
|
* @param mixed|self $as |
513
|
|
|
* @param mixed|self $cond |
514
|
|
|
* @return $this |
515
|
139 |
|
* |
516
|
|
|
* @since 1.3 |
517
|
139 |
|
*/ |
518
|
139 |
|
public function filter($input, $as, $cond) |
519
|
|
|
{ |
520
|
139 |
|
return $this->operator('$filter', ['input' => $input, 'as' => $as, 'cond' => $cond]); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Returns the value that results from applying an expression to the first |
525
|
|
|
* document in a group of documents that share the same group by key. Only |
526
|
|
|
* meaningful when documents are in a defined order. |
527
|
|
|
* |
528
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/first/ |
529
|
|
|
* @param mixed|self $expression |
530
|
|
|
* @return $this |
531
|
|
|
*/ |
532
|
|
|
public function first($expression) |
533
|
|
|
{ |
534
|
|
|
return $this->operator('$first', $expression); |
535
|
|
|
} |
536
|
|
|
|
537
|
3 |
|
/** |
538
|
|
|
* Returns the largest integer less than or equal to the specified number. |
539
|
3 |
|
* |
540
|
|
|
* The <number> expression can be any valid expression as long as it |
541
|
|
|
* resolves to a number. |
542
|
|
|
* |
543
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/floor/ |
544
|
|
|
* @param mixed|self $number |
545
|
|
|
* @return $this |
546
|
|
|
* |
547
|
|
|
* @since 1.3 |
548
|
|
|
*/ |
549
|
|
|
public function floor($number) |
550
|
|
|
{ |
551
|
2 |
|
return $this->operator('$floor', $number); |
552
|
|
|
} |
553
|
2 |
|
|
554
|
|
|
/** |
555
|
|
|
* @return array |
556
|
|
|
*/ |
557
|
|
|
public function getExpression() |
558
|
|
|
{ |
559
|
|
|
return $this->expr; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* Compares two values and returns: |
564
|
|
|
* true when the first value is greater than the second value. |
565
|
|
|
* false when the first value is less than or equivalent to the second |
566
|
|
|
* value. |
567
|
|
|
* |
568
|
3 |
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/gt/ |
569
|
|
|
* @param mixed|self $expression1 |
570
|
3 |
|
* @param mixed|self $expression2 |
571
|
|
|
* @return $this |
572
|
|
|
*/ |
573
|
|
|
public function gt($expression1, $expression2) |
574
|
|
|
{ |
575
|
|
|
return $this->operator('$gt', [$expression1, $expression2]); |
576
|
339 |
|
} |
577
|
|
|
|
578
|
339 |
|
/** |
579
|
|
|
* Compares two values and returns: |
580
|
|
|
* true when the first value is greater than or equivalent to the second |
581
|
|
|
* value. |
582
|
|
|
* false when the first value is less than the second value. |
583
|
|
|
* |
584
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/gte/ |
585
|
|
|
* @param mixed|self $expression1 |
586
|
|
|
* @param mixed|self $expression2 |
587
|
|
|
* @return $this |
588
|
|
|
*/ |
589
|
|
|
public function gte($expression1, $expression2) |
590
|
|
|
{ |
591
|
|
|
return $this->operator('$gte', [$expression1, $expression2]); |
592
|
3 |
|
} |
593
|
|
|
|
594
|
3 |
|
/** |
595
|
|
|
* Returns the hour portion of a date as a number between 0 and 23. |
596
|
|
|
* |
597
|
|
|
* The argument can be any expression as long as it resolves to a date. |
598
|
|
|
* |
599
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/hour/ |
600
|
|
|
* @param mixed|self $expression |
601
|
|
|
* @return $this |
602
|
|
|
*/ |
603
|
|
|
public function hour($expression) |
604
|
|
|
{ |
605
|
|
|
return $this->operator('$hour', $expression); |
606
|
|
|
} |
607
|
|
|
|
608
|
6 |
|
/** |
609
|
|
|
* Evaluates an expression and returns the value of the expression if the |
610
|
6 |
|
* expression evaluates to a non-null value. If the expression evaluates to |
611
|
|
|
* a null value, including instances of undefined values or missing fields, |
612
|
|
|
* returns the value of the replacement expression. |
613
|
|
|
* |
614
|
|
|
* The arguments can be any valid expression. |
615
|
|
|
* |
616
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/ifNull/ |
617
|
|
|
* @param mixed|self $expression |
618
|
|
|
* @param mixed|self $replacementExpression |
619
|
|
|
* @return $this |
620
|
|
|
*/ |
621
|
|
|
public function ifNull($expression, $replacementExpression) |
622
|
3 |
|
{ |
623
|
|
|
return $this->operator('$ifNull', [$expression, $replacementExpression]); |
624
|
3 |
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* Returns a boolean indicating whether a specified value is in an array. |
628
|
|
|
* |
629
|
|
|
* Unlike the $in query operator, the aggregation $in operator does not |
630
|
|
|
* support matching by regular expressions. |
631
|
|
|
* |
632
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/in/ |
633
|
|
|
* @since 1.5 |
634
|
|
|
* @param mixed|self $expression |
635
|
|
|
* @param mixed|self $arrayExpression |
636
|
|
|
* @return $this |
637
|
|
|
*/ |
638
|
|
|
public function in($expression, $arrayExpression) |
639
|
|
|
{ |
640
|
3 |
|
return $this->operator('$in', [$expression, $arrayExpression]); |
641
|
|
|
} |
642
|
3 |
|
|
643
|
|
|
/** |
644
|
|
|
* Searches an array for an occurence of a specified value and returns the |
645
|
|
|
* array index (zero-based) of the first occurence. If the value is not |
646
|
|
|
* found, returns -1. |
647
|
|
|
* |
648
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfArray/ |
649
|
|
|
* @since 1.5 |
650
|
|
|
* @param mixed|self $arrayExpression Can be any valid expression as long as it resolves to an array. |
651
|
|
|
* @param mixed|self $searchExpression Can be any valid expression. |
652
|
|
|
* @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. |
653
|
|
|
* @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. |
654
|
|
|
* @return $this |
655
|
|
|
*/ |
656
|
|
View Code Duplication |
public function indexOfArray($arrayExpression, $searchExpression, $start = null, $end = null) |
|
|
|
|
657
|
3 |
|
{ |
658
|
|
|
$args = [$arrayExpression, $searchExpression]; |
659
|
3 |
|
if ($start !== null) { |
660
|
|
|
$args[] = $start; |
661
|
|
|
|
662
|
|
|
if ($end !== null) { |
663
|
|
|
$args[] = $end; |
664
|
|
|
} |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
return $this->operator('$indexOfArray', $args); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* Searches a string for an occurence of a substring and returns the UTF-8 |
672
|
|
|
* byte index (zero-based) of the first occurence. If the substring is not |
673
|
|
|
* found, returns -1. |
674
|
|
|
* |
675
|
12 |
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfBytes/ |
676
|
|
|
* @since 1.5 |
677
|
12 |
|
* @param mixed|self $stringExpression Can be any valid expression as long as it resolves to a string. |
678
|
12 |
|
* @param mixed|self $substringExpression Can be any valid expression as long as it resolves to a string. |
679
|
6 |
|
* @param 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. |
680
|
|
|
* @param 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. |
681
|
6 |
|
* |
682
|
3 |
|
* @return $this |
683
|
|
|
*/ |
684
|
|
View Code Duplication |
public function indexOfBytes($stringExpression, $substringExpression, $start = null, $end = null) |
|
|
|
|
685
|
|
|
{ |
686
|
12 |
|
$args = [$stringExpression, $substringExpression]; |
687
|
|
|
if ($start !== null) { |
688
|
|
|
$args[] = $start; |
689
|
|
|
|
690
|
|
|
if ($end !== null) { |
691
|
|
|
$args[] = $end; |
692
|
|
|
} |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
return $this->operator('$indexOfBytes', $args); |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Searches a string for an occurence of a substring and returns the UTF-8 |
700
|
|
|
* code point index (zero-based) of the first occurence. If the substring is |
701
|
|
|
* not found, returns -1. |
702
|
|
|
* |
703
|
12 |
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfCP/ |
704
|
|
|
* @since 1.5 |
705
|
12 |
|
* @param mixed|self $stringExpression Can be any valid expression as long as it resolves to a string. |
706
|
12 |
|
* @param mixed|self $substringExpression Can be any valid expression as long as it resolves to a string. |
707
|
6 |
|
* @param 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. |
708
|
|
|
* @param 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. |
709
|
6 |
|
* |
710
|
3 |
|
* @return $this |
711
|
|
|
*/ |
712
|
|
View Code Duplication |
public function indexOfCP($stringExpression, $substringExpression, $start = null, $end = null) |
|
|
|
|
713
|
|
|
{ |
714
|
12 |
|
$args = [$stringExpression, $substringExpression]; |
715
|
|
|
if ($start !== null) { |
716
|
|
|
$args[] = $start; |
717
|
|
|
|
718
|
|
|
if ($end !== null) { |
719
|
|
|
$args[] = $end; |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
return $this->operator('$indexOfCP', $args); |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* Determines if the operand is an array. Returns a boolean. |
728
|
|
|
* |
729
|
|
|
* The <expression> can be any valid expression. |
730
|
|
|
* |
731
|
12 |
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/isArray/ |
732
|
|
|
* @param mixed|self $expression |
733
|
12 |
|
* @return $this |
734
|
12 |
|
* |
735
|
6 |
|
* @since 1.3 |
736
|
|
|
*/ |
737
|
6 |
|
public function isArray($expression) |
738
|
3 |
|
{ |
739
|
|
|
return $this->operator('$isArray', $expression); |
740
|
|
|
} |
741
|
|
|
|
742
|
12 |
|
/** |
743
|
|
|
* Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) |
744
|
|
|
* to 7 (for Sunday). |
745
|
|
|
* |
746
|
|
|
* The argument can be any expression as long as it resolves to a date. |
747
|
|
|
* |
748
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/isoDayOfWeek/ |
749
|
|
|
* @since 1.5 |
750
|
|
|
* @param mixed|self $expression |
751
|
|
|
* @return $this |
752
|
|
|
*/ |
753
|
|
|
public function isoDayOfWeek($expression) |
754
|
|
|
{ |
755
|
|
|
return $this->operator('$isoDayOfWeek', $expression); |
756
|
3 |
|
} |
757
|
|
|
|
758
|
3 |
|
/** |
759
|
|
|
* Returns the week number in ISO 8601 format, ranging from 1 to 53. |
760
|
|
|
* |
761
|
|
|
* Week numbers start at 1 with the week (Monday through Sunday) that |
762
|
|
|
* contains the year’s first Thursday. |
763
|
|
|
* |
764
|
|
|
* The argument can be any expression as long as it resolves to a date. |
765
|
|
|
* |
766
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/isoWeek/ |
767
|
|
|
* @since 1.5 |
768
|
|
|
* @param mixed|self $expression |
769
|
|
|
* @return $this |
770
|
|
|
*/ |
771
|
|
|
public function isoWeek($expression) |
772
|
3 |
|
{ |
773
|
|
|
return $this->operator('$isoWeek', $expression); |
774
|
3 |
|
} |
775
|
|
|
|
776
|
|
|
/** |
777
|
|
|
* Returns the year number in ISO 8601 format. |
778
|
|
|
* |
779
|
|
|
* The year starts with the Monday of week 1 (ISO 8601) and ends with the |
780
|
|
|
* Sunday of the last week (ISO 8601). |
781
|
|
|
* |
782
|
|
|
* The argument can be any expression as long as it resolves to a date. |
783
|
|
|
* |
784
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/isoWeek/ |
785
|
|
|
* @since 1.5 |
786
|
|
|
* @param mixed|self $expression |
787
|
|
|
* @return $this |
788
|
|
|
*/ |
789
|
|
|
public function isoWeekYear($expression) |
790
|
3 |
|
{ |
791
|
|
|
return $this->operator('$isoWeekYear', $expression); |
792
|
3 |
|
} |
793
|
|
|
|
794
|
|
|
/** |
795
|
|
|
* Returns the value that results from applying an expression to the last |
796
|
|
|
* document in a group of documents that share the same group by a field. |
797
|
|
|
* Only meaningful when documents are in a defined order. |
798
|
|
|
* |
799
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/last/ |
800
|
|
|
* @param mixed|self $expression |
801
|
|
|
* @return $this |
802
|
|
|
*/ |
803
|
|
|
public function last($expression) |
804
|
|
|
{ |
805
|
|
|
return $this->operator('$last', $expression); |
806
|
|
|
} |
807
|
|
|
|
808
|
3 |
|
/** |
809
|
|
|
* Binds variables for use in the specified expression, and returns the |
810
|
3 |
|
* result of the expression. |
811
|
|
|
* |
812
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/let/ |
813
|
|
|
* @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. |
814
|
|
|
* @param mixed|self $in The expression to evaluate. |
815
|
|
|
* @return $this |
816
|
|
|
*/ |
817
|
|
|
public function let($vars, $in) |
818
|
|
|
{ |
819
|
|
|
return $this->operator('$let', ['vars' => $vars, 'in' => $in]); |
820
|
|
|
} |
821
|
|
|
|
822
|
2 |
|
/** |
823
|
|
|
* Returns a value without parsing. Use for values that the aggregation |
824
|
2 |
|
* pipeline may interpret as an expression. |
825
|
|
|
* |
826
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/literal/ |
827
|
|
|
* @param mixed|self $value |
828
|
|
|
* @return $this |
829
|
|
|
*/ |
830
|
|
|
public function literal($value) |
831
|
|
|
{ |
832
|
|
|
return $this->operator('$literal', $value); |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
3 |
|
* Calculates the natural logarithm ln (i.e loge) of a number and returns |
837
|
|
|
* the result as a double. |
838
|
3 |
|
* |
839
|
|
|
* The <number> expression can be any valid expression as long as it |
840
|
|
|
* resolves to a non-negative number. |
841
|
|
|
* |
842
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/log/ |
843
|
|
|
* @param mixed|self $number |
844
|
|
|
* @return $this |
845
|
|
|
* |
846
|
|
|
* @since 1.3 |
847
|
|
|
*/ |
848
|
|
|
public function ln($number) |
849
|
3 |
|
{ |
850
|
|
|
return $this->operator('$ln', $number); |
851
|
3 |
|
} |
852
|
|
|
|
853
|
|
|
/** |
854
|
|
|
* Calculates the log of a number in the specified base and returns the |
855
|
|
|
* result as a double. |
856
|
|
|
* |
857
|
|
|
* The <number> expression can be any valid expression as long as it |
858
|
|
|
* resolves to a non-negative number. |
859
|
|
|
* The <base> expression can be any valid expression as long as it resolves |
860
|
|
|
* to a positive number greater than 1. |
861
|
|
|
* |
862
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/log/ |
863
|
|
|
* @param mixed|self $number |
864
|
|
|
* @param mixed|self $base |
865
|
|
|
* @return $this |
866
|
|
|
* |
867
|
3 |
|
* @since 1.3 |
868
|
|
|
*/ |
869
|
3 |
|
public function log($number, $base) |
870
|
|
|
{ |
871
|
|
|
return $this->operator('$log', [$number, $base]); |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
/** |
875
|
|
|
* Calculates the log base 10 of a number and returns the result as a double. |
876
|
|
|
* |
877
|
|
|
* The <number> expression can be any valid expression as long as it |
878
|
|
|
* resolves to a non-negative number. |
879
|
|
|
* |
880
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/log10/ |
881
|
|
|
* @param mixed|self $number |
882
|
|
|
* @return $this |
883
|
|
|
* |
884
|
|
|
* @since 1.3 |
885
|
|
|
*/ |
886
|
|
|
public function log10($number) |
887
|
|
|
{ |
888
|
3 |
|
return $this->operator('$log10', $number); |
889
|
|
|
} |
890
|
3 |
|
|
891
|
|
|
/** |
892
|
|
|
* Compares two values and returns: |
893
|
|
|
* true when the first value is less than the second value. |
894
|
|
|
* false when the first value is greater than or equivalent to the second |
895
|
|
|
* value. |
896
|
|
|
* |
897
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/lt/ |
898
|
|
|
* @param mixed|self $expression1 |
899
|
|
|
* @param mixed|self $expression2 |
900
|
|
|
* @return $this |
901
|
|
|
*/ |
902
|
|
|
public function lt($expression1, $expression2) |
903
|
|
|
{ |
904
|
|
|
return $this->operator('$lt', [$expression1, $expression2]); |
905
|
3 |
|
} |
906
|
|
|
|
907
|
3 |
|
/** |
908
|
|
|
* Compares two values and returns: |
909
|
|
|
* true when the first value is less than or equivalent to the second value. |
910
|
|
|
* false when the first value is greater than the second value. |
911
|
|
|
* |
912
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/lte/ |
913
|
|
|
* @param mixed|self $expression1 |
914
|
|
|
* @param mixed|self $expression2 |
915
|
|
|
* @return $this |
916
|
|
|
*/ |
917
|
|
|
public function lte($expression1, $expression2) |
918
|
|
|
{ |
919
|
|
|
return $this->operator('$lte', [$expression1, $expression2]); |
920
|
|
|
} |
921
|
4 |
|
|
922
|
|
|
/** |
923
|
4 |
|
* Applies an expression to each item in an array and returns an array with |
924
|
|
|
* the applied results. |
925
|
|
|
* |
926
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/map/ |
927
|
|
|
* @param mixed|self $input An expression that resolves to an array. |
928
|
|
|
* @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. |
929
|
|
|
* @param mixed|self $in The expression to apply to each item in the input array. The expression accesses the item by its variable name. |
930
|
|
|
* @return $this |
931
|
|
|
*/ |
932
|
|
|
public function map($input, $as, $in) |
933
|
|
|
{ |
934
|
|
|
return $this->operator('$map', ['input' => $input, 'as' => $as, 'in' => $in]); |
935
|
|
|
} |
936
|
6 |
|
|
937
|
|
|
/** |
938
|
6 |
|
* Returns the highest value that results from applying an expression to |
939
|
|
|
* each document in a group of documents that share the same group by key. |
940
|
|
|
* |
941
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/max/ |
942
|
|
|
* @param mixed|self $expression |
943
|
|
|
* @return $this |
944
|
|
|
*/ |
945
|
|
|
public function max($expression) |
946
|
|
|
{ |
947
|
|
|
return $this->operator('$max', $expression); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
/** |
951
|
3 |
|
* Returns the metadata associated with a document in a pipeline operations. |
952
|
|
|
* |
953
|
3 |
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/meta/ |
954
|
|
|
* @param $metaDataKeyword |
955
|
|
|
* @return $this |
956
|
|
|
*/ |
957
|
|
|
public function meta($metaDataKeyword) |
958
|
|
|
{ |
959
|
|
|
return $this->operator('$meta', $metaDataKeyword); |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* Returns the millisecond portion of a date as an integer between 0 and 999. |
964
|
3 |
|
* |
965
|
|
|
* The argument can be any expression as long as it resolves to a date. |
966
|
3 |
|
* |
967
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/millisecond/ |
968
|
|
|
* @param mixed|self $expression |
969
|
|
|
* @return $this |
970
|
|
|
*/ |
971
|
|
|
public function millisecond($expression) |
972
|
|
|
{ |
973
|
|
|
return $this->operator('$millisecond', $expression); |
974
|
|
|
} |
975
|
|
|
|
976
|
3 |
|
/** |
977
|
|
|
* Returns the lowest value that results from applying an expression to each |
978
|
3 |
|
* document in a group of documents that share the same group by key. |
979
|
|
|
* |
980
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/min/ |
981
|
|
|
* @param mixed|self $expression |
982
|
|
|
* @return $this |
983
|
|
|
*/ |
984
|
|
|
public function min($expression) |
985
|
|
|
{ |
986
|
|
|
return $this->operator('$min', $expression); |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
/** |
990
|
3 |
|
* Returns the minute portion of a date as a number between 0 and 59. |
991
|
|
|
* |
992
|
3 |
|
* The argument can be any expression as long as it resolves to a date. |
993
|
|
|
* |
994
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/minute/ |
995
|
|
|
* @param mixed|self $expression |
996
|
|
|
* @return $this |
997
|
|
|
*/ |
998
|
|
|
public function minute($expression) |
999
|
|
|
{ |
1000
|
|
|
return $this->operator('$minute', $expression); |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
3 |
|
/** |
1004
|
|
|
* Divides one number by another and returns the remainder. The first |
1005
|
3 |
|
* argument is divided by the second argument. |
1006
|
|
|
* |
1007
|
|
|
* The arguments can be any valid expression as long as they resolve to numbers. |
1008
|
|
|
* |
1009
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/mod/ |
1010
|
|
|
* @param mixed|self $expression1 |
1011
|
|
|
* @param mixed|self $expression2 |
1012
|
|
|
* @return $this |
1013
|
|
|
*/ |
1014
|
|
|
public function mod($expression1, $expression2) |
1015
|
|
|
{ |
1016
|
|
|
return $this->operator('$mod', [$expression1, $expression2]); |
1017
|
3 |
|
} |
1018
|
|
|
|
1019
|
3 |
|
/** |
1020
|
|
|
* Returns the month of a date as a number between 1 and 12. |
1021
|
|
|
* |
1022
|
|
|
* The argument can be any expression as long as it resolves to a date. |
1023
|
|
|
* |
1024
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/month/ |
1025
|
|
|
* @param mixed|self $expression |
1026
|
|
|
* @return $this |
1027
|
|
|
*/ |
1028
|
|
|
public function month($expression) |
1029
|
|
|
{ |
1030
|
|
|
return $this->operator('$month', $expression); |
1031
|
|
|
} |
1032
|
|
|
|
1033
|
3 |
|
/** |
1034
|
|
|
* Multiplies numbers together and returns the result. |
1035
|
3 |
|
* |
1036
|
|
|
* The arguments can be any valid expression as long as they resolve to numbers. |
1037
|
|
|
* |
1038
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/multiply/ |
1039
|
|
|
* @param mixed|self $expression1 |
1040
|
|
|
* @param mixed|self $expression2 |
1041
|
|
|
* @param mixed|self $expression3,... Additional expressions |
|
|
|
|
1042
|
|
|
* @return $this |
1043
|
|
|
*/ |
1044
|
|
|
public function multiply($expression1, $expression2 /* , $expression3, ... */) |
|
|
|
|
1045
|
|
|
{ |
1046
|
|
|
return $this->operator('$multiply', func_get_args()); |
1047
|
3 |
|
} |
1048
|
|
|
|
1049
|
3 |
|
/** |
1050
|
|
|
* Compares two values and returns: |
1051
|
|
|
* true when the values are not equivalent. |
1052
|
|
|
* false when the values are equivalent. |
1053
|
|
|
* |
1054
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/ne/ |
1055
|
|
|
* @param mixed|self $expression1 |
1056
|
|
|
* @param mixed|self $expression2 |
1057
|
|
|
* @return $this |
1058
|
|
|
*/ |
1059
|
|
|
public function ne($expression1, $expression2) |
1060
|
|
|
{ |
1061
|
|
|
return $this->operator('$ne', [$expression1, $expression2]); |
1062
|
|
|
} |
1063
|
13 |
|
|
1064
|
|
|
/** |
1065
|
13 |
|
* Evaluates a boolean and returns the opposite boolean value. |
1066
|
|
|
* |
1067
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/not/ |
1068
|
|
|
* @param mixed|self $expression |
1069
|
|
|
* @return $this |
1070
|
|
|
*/ |
1071
|
|
|
public function not($expression) |
1072
|
|
|
{ |
1073
|
|
|
return $this->operator('$not', $expression); |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
/** |
1077
|
|
|
* Raises a number to the specified exponent and returns the result. |
1078
|
4 |
|
* |
1079
|
|
|
* The <number> expression can be any valid expression as long as it |
1080
|
4 |
|
* resolves to a non-negative number. |
1081
|
|
|
* The <exponent> expression can be any valid expression as long as it |
1082
|
|
|
* resolves to a number. |
1083
|
|
|
* |
1084
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/pow/ |
1085
|
|
|
* @param mixed|self $number |
1086
|
|
|
* @param mixed|self $exponent |
1087
|
|
|
* @return $this |
1088
|
|
|
* |
1089
|
|
|
* @since 1.3 |
1090
|
3 |
|
*/ |
1091
|
|
|
public function pow($number, $exponent) |
1092
|
3 |
|
{ |
1093
|
|
|
return $this->operator('$pow', [$number, $exponent]); |
1094
|
|
|
} |
1095
|
|
|
|
1096
|
|
|
/** |
1097
|
|
|
* Returns an array of all values that result from applying an expression to |
1098
|
|
|
* each document in a group of documents that share the same group by key. |
1099
|
|
|
* |
1100
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/push/ |
1101
|
|
|
* @param mixed|self $expression |
1102
|
|
|
* @return $this |
1103
|
|
|
*/ |
1104
|
|
|
public function push($expression) |
1105
|
|
|
{ |
1106
|
|
|
return $this->operator('$push', $expression); |
1107
|
|
|
} |
1108
|
|
|
|
1109
|
|
|
/** |
1110
|
3 |
|
* Returns an array whose elements are a generated sequence of numbers. |
1111
|
|
|
* |
1112
|
3 |
|
* $range generates the sequence from the specified starting number by successively incrementing the starting number by the specified step value up to but not including the end point. |
1113
|
|
|
* |
1114
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/range/ |
1115
|
|
|
* @since 1.5 |
1116
|
|
|
* @param mixed|self $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. |
1117
|
|
|
* @param mixed|self $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. |
1118
|
|
|
* @param mixed|self $step Optional. An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. |
1119
|
|
|
* @return $this |
1120
|
|
|
*/ |
1121
|
|
|
public function range($start, $end, $step = 1) |
1122
|
|
|
{ |
1123
|
2 |
|
return $this->operator('$range', [$start, $end, $step]); |
1124
|
|
|
} |
1125
|
2 |
|
|
1126
|
|
|
/** |
1127
|
|
|
* Applies an expression to each element in an array and combines them into |
1128
|
|
|
* a single value. |
1129
|
|
|
* |
1130
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/reduce/ |
1131
|
|
|
* @since 1.5 |
1132
|
|
|
* @param mixed|self $input Can be any valid expression that resolves to an array. |
1133
|
|
|
* @param mixed|self $initialValue The initial cumulative value set before in is applied to the first element of the input array. |
1134
|
|
|
* @param mixed|self $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. |
1135
|
|
|
* @return $this |
1136
|
|
|
*/ |
1137
|
|
|
public function reduce($input, $initialValue, $in) |
1138
|
|
|
{ |
1139
|
|
|
return $this->operator('$reduce', ['input' => $input, 'initialValue' => $initialValue, 'in' => $in]); |
1140
|
6 |
|
} |
1141
|
|
|
|
1142
|
6 |
|
/** |
1143
|
|
|
* Accepts an array expression as an argument and returns an array with the |
1144
|
|
|
* elements in reverse order. |
1145
|
|
|
* |
1146
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/reverseArray/ |
1147
|
|
|
* @since 1.5 |
1148
|
|
|
* @param mixed|self $expression |
1149
|
|
|
* @return $this |
1150
|
|
|
*/ |
1151
|
|
|
public function reverseArray($expression) |
1152
|
|
|
{ |
1153
|
|
|
return $this->operator('$reverseArray', $expression); |
1154
|
|
|
} |
1155
|
|
|
|
1156
|
3 |
|
/** |
1157
|
|
|
* Returns the second portion of a date as a number between 0 and 59, but |
1158
|
3 |
|
* can be 60 to account for leap seconds. |
1159
|
|
|
* |
1160
|
|
|
* The argument can be any expression as long as it resolves to a date. |
1161
|
|
|
* |
1162
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/second/ |
1163
|
|
|
* @param mixed|self $expression |
1164
|
|
|
* @return $this |
1165
|
|
|
*/ |
1166
|
|
|
public function second($expression) |
1167
|
|
|
{ |
1168
|
|
|
return $this->operator('$second', $expression); |
1169
|
|
|
} |
1170
|
3 |
|
|
1171
|
|
|
/** |
1172
|
3 |
|
* Takes two sets and returns an array containing the elements that only |
1173
|
|
|
* exist in the first set. |
1174
|
|
|
* |
1175
|
|
|
* The arguments can be any valid expression as long as they each resolve to an array. |
1176
|
|
|
* |
1177
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/setDifference/ |
1178
|
|
|
* @param mixed|self $expression1 |
1179
|
|
|
* @param mixed|self $expression2 |
1180
|
|
|
* @return $this |
1181
|
|
|
*/ |
1182
|
|
|
public function setDifference($expression1, $expression2) |
1183
|
|
|
{ |
1184
|
|
|
return $this->operator('$setDifference', [$expression1, $expression2]); |
1185
|
3 |
|
} |
1186
|
|
|
|
1187
|
3 |
|
/** |
1188
|
|
|
* Compares two or more arrays and returns true if they have the same |
1189
|
|
|
* distinct elements and false otherwise. |
1190
|
|
|
* |
1191
|
|
|
* The arguments can be any valid expression as long as they each resolve to an array. |
1192
|
|
|
* |
1193
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/setEquals/ |
1194
|
|
|
* @param mixed|self $expression1 |
1195
|
|
|
* @param mixed|self $expression2 |
1196
|
|
|
* @param mixed|self $expression3,... Additional sets |
|
|
|
|
1197
|
|
|
* @return $this |
1198
|
|
|
*/ |
1199
|
|
|
public function setEquals($expression1, $expression2 /* , $expression3, ... */) |
|
|
|
|
1200
|
|
|
{ |
1201
|
3 |
|
return $this->operator('$setEquals', func_get_args()); |
1202
|
|
|
} |
1203
|
3 |
|
|
1204
|
|
|
/** |
1205
|
|
|
* Takes two or more arrays and returns an array that contains the elements |
1206
|
|
|
* that appear in every input array. |
1207
|
|
|
* |
1208
|
|
|
* The arguments can be any valid expression as long as they each resolve to an array. |
1209
|
|
|
* |
1210
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/setIntersection/ |
1211
|
|
|
* @param mixed|self $expression1 |
1212
|
|
|
* @param mixed|self $expression2 |
1213
|
|
|
* @param mixed|self $expression3,... Additional sets |
|
|
|
|
1214
|
|
|
* @return $this |
1215
|
|
|
*/ |
1216
|
|
|
public function setIntersection($expression1, $expression2 /* , $expression3, ... */) |
|
|
|
|
1217
|
|
|
{ |
1218
|
6 |
|
return $this->operator('$setIntersection', func_get_args()); |
1219
|
|
|
} |
1220
|
6 |
|
|
1221
|
|
|
/** |
1222
|
|
|
* Takes two arrays and returns true when the first array is a subset of the |
1223
|
|
|
* second, including when the first array equals the second array, and false otherwise. |
1224
|
|
|
* |
1225
|
|
|
* The arguments can be any valid expression as long as they each resolve to an array. |
1226
|
|
|
* |
1227
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/setIsSubset/ |
1228
|
|
|
* @param mixed|self $expression1 |
1229
|
|
|
* @param mixed|self $expression2 |
1230
|
|
|
* @return $this |
1231
|
|
|
*/ |
1232
|
|
|
public function setIsSubset($expression1, $expression2) |
1233
|
|
|
{ |
1234
|
|
|
return $this->operator('$setIsSubset', [$expression1, $expression2]); |
1235
|
6 |
|
} |
1236
|
|
|
|
1237
|
6 |
|
/** |
1238
|
|
|
* Takes two or more arrays and returns an array containing the elements |
1239
|
|
|
* that appear in any input array. |
1240
|
|
|
* |
1241
|
|
|
* The arguments can be any valid expression as long as they each resolve to an array. |
1242
|
|
|
* |
1243
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/setUnion/ |
1244
|
|
|
* @param mixed|self $expression1 |
1245
|
|
|
* @param mixed|self $expression2 |
1246
|
|
|
* @param mixed|self $expression3,... Additional sets |
|
|
|
|
1247
|
|
|
* @return $this |
1248
|
|
|
*/ |
1249
|
|
|
public function setUnion($expression1, $expression2 /* , $expression3, ... */) |
|
|
|
|
1250
|
|
|
{ |
1251
|
3 |
|
return $this->operator('$setUnion', func_get_args()); |
1252
|
|
|
} |
1253
|
3 |
|
|
1254
|
|
|
/** |
1255
|
|
|
* Counts and returns the total the number of items in an array. |
1256
|
|
|
* |
1257
|
|
|
* The argument can be any expression as long as it resolves to an array. |
1258
|
|
|
* |
1259
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/size/ |
1260
|
|
|
* @param mixed|self $expression |
1261
|
|
|
* @return $this |
1262
|
|
|
*/ |
1263
|
|
|
public function size($expression) |
1264
|
|
|
{ |
1265
|
|
|
return $this->operator('$size', $expression); |
1266
|
|
|
} |
1267
|
|
|
|
1268
|
6 |
|
/** |
1269
|
|
|
* Returns a subset of an array. |
1270
|
6 |
|
* |
1271
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/slice/ |
1272
|
|
|
* @param mixed|self $array |
1273
|
|
|
* @param mixed|self $n |
1274
|
|
|
* @param mixed|self|null $position |
1275
|
|
|
* @return $this |
1276
|
|
|
* |
1277
|
|
|
* @since 1.3 |
1278
|
|
|
*/ |
1279
|
|
|
public function slice($array, $n, $position = null) |
1280
|
|
|
{ |
1281
|
|
|
if ($position === null) { |
1282
|
3 |
|
return $this->operator('$slice', [$array, $n]); |
1283
|
|
|
} |
1284
|
3 |
|
|
1285
|
|
|
return $this->operator('$slice', [$array, $position, $n]); |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
|
/** |
1289
|
|
|
* Divides a string into an array of substrings based on a delimiter. |
1290
|
|
|
* |
1291
|
|
|
* $split removes the delimiter and returns the resulting substrings as |
1292
|
|
|
* elements of an array. If the delimiter is not found in the string, $split |
1293
|
|
|
* returns the original string as the only element of an array. |
1294
|
|
|
* |
1295
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/split/ |
1296
|
|
|
* @since 1.5 |
1297
|
|
|
* @param mixed|self $string The string to be split. Can be any valid expression as long as it resolves to a string. |
1298
|
6 |
|
* @param mixed|self $delimiter The delimiter to use when splitting the string expression. Can be any valid expression as long as it resolves to a string. |
1299
|
|
|
* |
1300
|
6 |
|
* @return $this |
1301
|
3 |
|
*/ |
1302
|
|
|
public function split($string, $delimiter) |
1303
|
|
|
{ |
1304
|
3 |
|
return $this->operator('$split', [$string, $delimiter]); |
1305
|
|
|
} |
1306
|
|
|
|
1307
|
|
|
/** |
1308
|
|
|
* Calculates the square root of a positive number and returns the result as |
1309
|
|
|
* a double. |
1310
|
|
|
* |
1311
|
|
|
* The argument can be any valid expression as long as it resolves to a |
1312
|
|
|
* non-negative number. |
1313
|
|
|
* |
1314
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/sqrt/ |
1315
|
|
|
* @param mixed|self $expression |
1316
|
|
|
* @return $this |
1317
|
|
|
*/ |
1318
|
|
|
public function sqrt($expression) |
1319
|
|
|
{ |
1320
|
|
|
return $this->operator('$sqrt', $expression); |
1321
|
3 |
|
} |
1322
|
|
|
|
1323
|
3 |
|
/** |
1324
|
|
|
* Calculates the population standard deviation of the input values. |
1325
|
|
|
* |
1326
|
|
|
* The arguments can be any expression as long as it resolves to an array. |
1327
|
|
|
* |
1328
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/ |
1329
|
|
|
* @param mixed|self $expression1 |
1330
|
|
|
* @param mixed|self $expression2,... Additional samples |
|
|
|
|
1331
|
|
|
* @return $this |
1332
|
|
|
* |
1333
|
|
|
* @since 1.3 |
1334
|
|
|
*/ |
1335
|
|
|
public function stdDevPop($expression1 /* , $expression2, ... */) |
1336
|
|
|
{ |
1337
|
3 |
|
$expression = (func_num_args() === 1) ? $expression1 : func_get_args(); |
1338
|
|
|
|
1339
|
3 |
|
return $this->operator('$stdDevPop', $expression); |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
/** |
1343
|
|
|
* Calculates the sample standard deviation of the input values. |
1344
|
|
|
* |
1345
|
|
|
* The arguments can be any expression as long as it resolves to an array. |
1346
|
|
|
* |
1347
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/ |
1348
|
|
|
* @param mixed|self $expression1 |
1349
|
|
|
* @param mixed|self $expression2,... Additional samples |
|
|
|
|
1350
|
|
|
* @return $this |
1351
|
|
|
* |
1352
|
|
|
* @since 1.3 |
1353
|
|
|
*/ |
1354
|
5 |
|
public function stdDevSamp($expression1 /* , $expression2, ... */) |
1355
|
|
|
{ |
1356
|
5 |
|
$expression = (func_num_args() === 1) ? $expression1 : func_get_args(); |
1357
|
|
|
|
1358
|
5 |
|
return $this->operator('$stdDevSamp', $expression); |
1359
|
|
|
} |
1360
|
|
|
|
1361
|
|
|
/** |
1362
|
|
|
* Performs case-insensitive comparison of two strings. Returns |
1363
|
|
|
* 1 if first string is “greater than” the second string. |
1364
|
|
|
* 0 if the two strings are equal. |
1365
|
|
|
* -1 if the first string is “less than” the second string. |
1366
|
|
|
* |
1367
|
|
|
* The arguments can be any valid expression as long as they resolve to strings. |
1368
|
|
|
* |
1369
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/strcasecmp/ |
1370
|
|
|
* @param mixed|self $expression1 |
1371
|
|
|
* @param mixed|self $expression2 |
1372
|
|
|
* @return $this |
1373
|
5 |
|
*/ |
1374
|
|
|
public function strcasecmp($expression1, $expression2) |
1375
|
5 |
|
{ |
1376
|
|
|
return $this->operator('$strcasecmp', [$expression1, $expression2]); |
1377
|
5 |
|
} |
1378
|
|
|
|
1379
|
|
|
/** |
1380
|
|
|
* Returns the number of UTF-8 encoded bytes in the specified string. |
1381
|
|
|
* |
1382
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/strLenBytes/ |
1383
|
|
|
* @since 1.5 |
1384
|
|
|
* @param mixed|self $string |
1385
|
|
|
* |
1386
|
|
|
* @return $this |
1387
|
|
|
*/ |
1388
|
|
|
public function strLenBytes($string) |
1389
|
|
|
{ |
1390
|
|
|
return $this->operator('$strLenBytes', $string); |
1391
|
|
|
} |
1392
|
|
|
|
1393
|
3 |
|
/** |
1394
|
|
|
* Returns the number of UTF-8 code points in the specified string. |
1395
|
3 |
|
* |
1396
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/strLenCP/ |
1397
|
|
|
* @since 1.5 |
1398
|
|
|
* @param mixed|self $string |
1399
|
|
|
* |
1400
|
|
|
* @return $this |
1401
|
|
|
*/ |
1402
|
|
|
public function strLenCP($string) |
1403
|
|
|
{ |
1404
|
|
|
return $this->operator('$strLenCP', $string); |
1405
|
|
|
} |
1406
|
|
|
|
1407
|
3 |
|
/** |
1408
|
|
|
* Returns a substring of a string, starting at a specified index position |
1409
|
3 |
|
* and including the specified number of characters. The index is zero-based. |
1410
|
|
|
* |
1411
|
|
|
* The arguments can be any valid expression as long as long as the first argument resolves to a string, and the second and third arguments resolve to integers. |
1412
|
|
|
* |
1413
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/substr/ |
1414
|
|
|
* @param mixed|self $string |
1415
|
|
|
* @param mixed|self $start |
1416
|
|
|
* @param mixed|self $length |
1417
|
|
|
* @return $this |
1418
|
|
|
*/ |
1419
|
|
|
public function substr($string, $start, $length) |
1420
|
|
|
{ |
1421
|
3 |
|
return $this->operator('$substr', [$string, $start, $length]); |
1422
|
|
|
} |
1423
|
3 |
|
|
1424
|
|
|
/** |
1425
|
|
|
* Returns the substring of a string. |
1426
|
|
|
* |
1427
|
|
|
* The substring starts with the character at the specified UTF-8 byte index |
1428
|
|
|
* (zero-based) in the string and continues for the number of bytes |
1429
|
|
|
* specified. |
1430
|
|
|
* |
1431
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/substrBytes/ |
1432
|
|
|
* @since 1.5 |
1433
|
|
|
* @param mixed|self $string The string from which the substring will be extracted. Can be any valid expression as long as it resolves to a string. |
1434
|
|
|
* @param mixed|self $start Indicates the starting point of the substring. Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer. |
1435
|
|
|
* @param mixed|self $count Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer. |
1436
|
|
|
* |
1437
|
|
|
* @return $this |
1438
|
3 |
|
*/ |
1439
|
|
|
public function substrBytes($string, $start, $count) |
1440
|
3 |
|
{ |
1441
|
|
|
return $this->operator('$substrBytes', [$string, $start, $count]); |
1442
|
|
|
} |
1443
|
|
|
|
1444
|
|
|
/** |
1445
|
|
|
* Returns the substring of a string. |
1446
|
|
|
* |
1447
|
|
|
* The substring starts with the character at the specified UTF-8 code point |
1448
|
|
|
* (CP) index (zero-based) in the string for the number of code points |
1449
|
|
|
* specified. |
1450
|
|
|
* |
1451
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/substrBytes/ |
1452
|
|
|
* @since 1.5 |
1453
|
|
|
* @param mixed|self $string The string from which the substring will be extracted. Can be any valid expression as long as it resolves to a string. |
1454
|
|
|
* @param mixed|self $start Indicates the starting point of the substring. Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer. |
1455
|
|
|
* @param mixed|self $count Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer. |
1456
|
|
|
* |
1457
|
|
|
* @return $this |
1458
|
3 |
|
*/ |
1459
|
|
|
public function substrCP($string, $start, $count) |
1460
|
3 |
|
{ |
1461
|
|
|
return $this->operator('$substrCP', [$string, $start, $count]); |
1462
|
|
|
} |
1463
|
|
|
|
1464
|
|
|
/** |
1465
|
|
|
* Subtracts two numbers to return the difference. The second argument is |
1466
|
|
|
* subtracted from the first argument. |
1467
|
|
|
* |
1468
|
|
|
* The arguments can be any valid expression as long as they resolve to numbers and/or dates. |
1469
|
|
|
* |
1470
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/subtract/ |
1471
|
|
|
* @param mixed|self $expression1 |
1472
|
|
|
* @param mixed|self $expression2 |
1473
|
|
|
* @return $this |
1474
|
|
|
*/ |
1475
|
|
|
public function subtract($expression1, $expression2) |
1476
|
|
|
{ |
1477
|
|
|
return $this->operator('$subtract', [$expression1, $expression2]); |
1478
|
3 |
|
} |
1479
|
|
|
|
1480
|
3 |
|
/** |
1481
|
|
|
* Calculates and returns the sum of all the numeric values that result from |
1482
|
|
|
* applying a specified expression to each document in a group of documents |
1483
|
|
|
* that share the same group by key. Ignores nun-numeric values. |
1484
|
|
|
* |
1485
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/ |
1486
|
|
|
* @param mixed|self $expression |
1487
|
|
|
* @return $this |
1488
|
|
|
*/ |
1489
|
|
|
public function sum($expression) |
1490
|
|
|
{ |
1491
|
|
|
return $this->operator('$sum', $expression); |
1492
|
|
|
} |
1493
|
|
|
|
1494
|
3 |
|
/** |
1495
|
|
|
* Converts a string to lowercase, returning the result. |
1496
|
3 |
|
* |
1497
|
|
|
* The argument can be any expression as long as it resolves to a string. |
1498
|
|
|
* |
1499
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/toLower/ |
1500
|
|
|
* @param mixed|self $expression |
1501
|
|
|
* @return $this |
1502
|
|
|
*/ |
1503
|
|
|
public function toLower($expression) |
1504
|
|
|
{ |
1505
|
|
|
return $this->operator('$toLower', $expression); |
1506
|
|
|
} |
1507
|
|
|
|
1508
|
9 |
|
/** |
1509
|
|
|
* Converts a string to uppercase, returning the result. |
1510
|
9 |
|
* |
1511
|
|
|
* The argument can be any expression as long as it resolves to a string. |
1512
|
|
|
* |
1513
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/toUpper/ |
1514
|
|
|
* @param mixed|self $expression |
1515
|
|
|
* @return $this |
1516
|
|
|
*/ |
1517
|
|
|
public function toUpper($expression) |
1518
|
|
|
{ |
1519
|
|
|
return $this->operator('$toUpper', $expression); |
1520
|
|
|
} |
1521
|
|
|
|
1522
|
3 |
|
/** |
1523
|
|
|
* Truncates a number to its integer. |
1524
|
3 |
|
* |
1525
|
|
|
* The <number> expression can be any valid expression as long as it |
1526
|
|
|
* resolves to a number. |
1527
|
|
|
* |
1528
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/trunc/ |
1529
|
|
|
* @param mixed|self $number |
1530
|
|
|
* @return $this |
1531
|
|
|
* |
1532
|
|
|
* @since 1.3 |
1533
|
|
|
*/ |
1534
|
|
|
public function trunc($number) |
1535
|
|
|
{ |
1536
|
3 |
|
return $this->operator('$trunc', $number); |
1537
|
|
|
} |
1538
|
3 |
|
|
1539
|
|
|
/** |
1540
|
|
|
* Returns a string that specifies the BSON type of the argument. |
1541
|
|
|
* |
1542
|
|
|
* The argument can be any valid expression. |
1543
|
|
|
* |
1544
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/type/ |
1545
|
|
|
* @since 1.5 |
1546
|
|
|
* @param mixed|self $expression |
1547
|
|
|
* |
1548
|
|
|
* @return $this |
1549
|
|
|
*/ |
1550
|
|
|
public function type($expression) |
1551
|
|
|
{ |
1552
|
|
|
return $this->operator('$type', $expression); |
1553
|
3 |
|
} |
1554
|
|
|
|
1555
|
3 |
|
/** |
1556
|
|
|
* Returns the week of the year for a date as a number between 0 and 53. |
1557
|
|
|
* |
1558
|
|
|
* The argument can be any expression as long as it resolves to a date. |
1559
|
|
|
* |
1560
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/week/ |
1561
|
|
|
* @param mixed|self $expression |
1562
|
|
|
* @return $this |
1563
|
|
|
*/ |
1564
|
|
|
public function week($expression) |
1565
|
|
|
{ |
1566
|
|
|
return $this->operator('$week', $expression); |
1567
|
|
|
} |
1568
|
|
|
|
1569
|
3 |
|
/** |
1570
|
|
|
* Returns the year portion of a date. |
1571
|
3 |
|
* |
1572
|
|
|
* The argument can be any expression as long as it resolves to a date. |
1573
|
|
|
* |
1574
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/year/ |
1575
|
|
|
* @param mixed|self $expression |
1576
|
|
|
* @return $this |
1577
|
|
|
*/ |
1578
|
|
|
public function year($expression) |
1579
|
|
|
{ |
1580
|
|
|
return $this->operator('$year', $expression); |
1581
|
|
|
} |
1582
|
|
|
|
1583
|
3 |
|
/** |
1584
|
|
|
* Transposes an array of input arrays so that the first element of the |
1585
|
3 |
|
* output array would be an array containing, the first element of the first |
1586
|
|
|
* input array, the first element of the second input array, etc. |
1587
|
|
|
* |
1588
|
|
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/zip/ |
1589
|
|
|
* @since 1.5 |
1590
|
|
|
* @param mixed|self $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. |
1591
|
|
|
* @param bool|null $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. |
1592
|
|
|
* @param mixed|self|null $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. |
1593
|
|
|
* @return $this |
1594
|
|
|
*/ |
1595
|
|
|
public function zip($inputs, $useLongestLength = null, $defaults = null) |
1596
|
|
|
{ |
1597
|
4 |
|
$args = ['inputs' => $inputs]; |
1598
|
|
|
if ($useLongestLength !== null) { |
1599
|
4 |
|
$args['useLongestLength'] = $useLongestLength; |
1600
|
|
|
} |
1601
|
|
|
if ($defaults !== null) { |
1602
|
|
|
$args['defaults'] = $defaults; |
1603
|
|
|
} |
1604
|
|
|
|
1605
|
|
|
return $this->operator('$zip', $args); |
1606
|
|
|
} |
1607
|
|
|
|
1608
|
|
|
|
1609
|
|
|
/** |
1610
|
|
|
* @param mixed|self $expression |
1611
|
|
|
* @return mixed |
1612
|
|
|
*/ |
1613
|
|
|
private function ensureArray($expression) |
1614
|
9 |
|
{ |
1615
|
|
|
if (is_string($expression) && substr($expression, 0, 1) === '$') { |
1616
|
9 |
|
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1)); |
1617
|
9 |
|
} elseif (is_array($expression)) { |
1618
|
6 |
|
return array_map([$this, 'ensureArray'], $expression); |
1619
|
|
|
} elseif ($expression instanceof self) { |
1620
|
9 |
|
return $expression->getExpression(); |
1621
|
3 |
|
} |
1622
|
|
|
|
1623
|
|
|
// Convert PHP types to MongoDB types for everything else |
1624
|
9 |
|
return Type::convertPHPToDatabaseValue($expression); |
1625
|
|
|
} |
1626
|
|
|
|
1627
|
|
|
/** |
1628
|
|
|
* @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister |
1629
|
|
|
*/ |
1630
|
|
|
private function getDocumentPersister() |
1631
|
|
|
{ |
1632
|
343 |
|
return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name); |
|
|
|
|
1633
|
|
|
} |
1634
|
343 |
|
|
1635
|
341 |
|
/** |
1636
|
217 |
|
* Defines an operator and value on the expression. |
1637
|
209 |
|
* |
1638
|
87 |
|
* If there is a current field, the operator will be set on it; otherwise, |
1639
|
20 |
|
* the operator is set at the top level of the query. |
1640
|
|
|
* |
1641
|
|
|
* @param string $operator |
1642
|
|
|
* @param array|self[]|self $expression |
1643
|
85 |
|
* @return $this |
1644
|
|
|
*/ |
1645
|
|
|
private function operator($operator, $expression) |
1646
|
|
|
{ |
1647
|
|
|
if ($this->currentField) { |
1648
|
|
|
$this->expr[$this->currentField][$operator] = $this->ensureArray($expression); |
1649
|
343 |
|
} else { |
1650
|
|
|
$this->expr[$operator] = $this->ensureArray($expression); |
1651
|
343 |
|
} |
1652
|
|
|
|
1653
|
|
|
return $this; |
1654
|
|
|
} |
1655
|
|
|
|
1656
|
|
|
/** |
1657
|
|
|
* Ensure that a current field has been set. |
1658
|
|
|
* |
1659
|
|
|
* @param string $method |
1660
|
|
|
* |
1661
|
|
|
* @throws \LogicException if a current field has not been set |
1662
|
|
|
*/ |
1663
|
|
|
private function requiresCurrentField($method = null) |
1664
|
341 |
|
{ |
1665
|
|
|
if ( ! $this->currentField) { |
1666
|
341 |
|
throw new \LogicException(($method ?: 'This method') . ' requires you set a current field using field().'); |
1667
|
137 |
|
} |
1668
|
|
|
} |
1669
|
212 |
|
|
1670
|
|
|
/** |
1671
|
|
|
* @param string $method |
1672
|
341 |
|
* |
1673
|
|
|
* @throws \BadMethodCallException if there is no current switch operator |
1674
|
|
|
*/ |
1675
|
|
|
private function requiresSwitchStatement($method = null) |
1676
|
|
|
{ |
1677
|
|
|
$message = ($method ?: 'This method') . ' requires a valid switch statement (call switch() first).'; |
1678
|
|
|
|
1679
|
|
|
if ($this->currentField) { |
1680
|
|
|
if (! isset($this->expr[$this->currentField]['$switch'])) { |
1681
|
|
|
throw new \BadMethodCallException($message); |
1682
|
12 |
|
} |
1683
|
|
|
} elseif (! isset($this->expr['$switch'])) { |
1684
|
12 |
|
throw new \BadMethodCallException($message); |
1685
|
1 |
|
} |
1686
|
|
|
} |
1687
|
11 |
|
|
1688
|
|
|
/** |
1689
|
|
|
* Evaluates a series of case expressions. When it finds an expression which |
1690
|
|
|
* evaluates to true, $switch executes a specified expression and breaks out |
1691
|
|
|
* of the control flow. |
1692
|
|
|
* |
1693
|
|
|
* To add statements, use the {@link case()}, {@link then()} and |
1694
|
8 |
|
* {@link default()} methods. |
1695
|
|
|
* |
1696
|
8 |
|
* @return $this |
1697
|
|
|
*/ |
1698
|
8 |
|
public function switch() |
1699
|
|
|
{ |
1700
|
|
|
$this->operator('$switch', []); |
1701
|
|
|
|
1702
|
8 |
|
return $this; |
1703
|
4 |
|
} |
1704
|
|
|
|
1705
|
4 |
|
/** |
1706
|
|
|
* Adds a case statement for the current branch of the $switch operator. |
1707
|
|
|
* |
1708
|
|
|
* Requires {@link case()} to be called first. The argument can be any valid |
1709
|
|
|
* expression. |
1710
|
|
|
* |
1711
|
|
|
* @param mixed|self $expression |
1712
|
|
|
* |
1713
|
|
|
* @return $this |
1714
|
|
|
*/ |
1715
|
|
|
public function then($expression) |
1716
|
|
|
{ |
1717
|
|
|
if (! is_array($this->switchBranch)) { |
1718
|
|
|
throw new \BadMethodCallException(static::class . '::then requires a valid case statement (call case() first).'); |
1719
|
4 |
|
} |
1720
|
|
|
|
1721
|
4 |
|
$this->switchBranch['then'] = $expression; |
1722
|
|
|
|
1723
|
4 |
|
if ($this->currentField) { |
1724
|
|
|
$this->expr[$this->currentField]['$switch']['branches'][] = $this->ensureArray($this->switchBranch); |
1725
|
|
|
} else { |
1726
|
|
|
$this->expr['$switch']['branches'][] = $this->ensureArray($this->switchBranch); |
1727
|
|
|
} |
1728
|
|
|
|
1729
|
|
|
$this->switchBranch = null; |
|
|
|
|
1730
|
|
|
|
1731
|
|
|
return $this; |
1732
|
|
|
} |
1733
|
|
|
|
1734
|
|
|
} |
1735
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.