Skip to content

Commit 1e6f949

Browse files
authored
Merge pull request #2048 from Steveb-p/patch-1
Show how to pass expression as array
2 parents d5c9e06 + 5db4d73 commit 1e6f949

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/en/reference/aggregation-builder.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,26 @@ specifies all existing fields in the input documents and adds the new fields.
258258
->field('purchaseYear')
259259
->year('$purchaseDate');
260260
261+
You can also pass expressions as arrays:
262+
263+
.. code-block:: php
264+
265+
<?php
266+
267+
$builder = $dm->createAggregationBuilder(\Documents\Orders::class);
268+
$builder
269+
->addFields()
270+
->field('purchaseYear')
271+
->expression(['$year' => '$purchaseDate'])
272+
->field('multiply')
273+
->expression(['$multiply' => ['$price', 2 ] ]);
274+
275+
This allows usage of any expression operators introduced by MongoDB, even
276+
if Doctrine ODM does not yet wrap it with convenience methods.
277+
278+
You can see all available expression operators at MongoDB documentation
279+
`here <https://docs.mongodb.com/manual/reference/operator/aggregation/>`_.
280+
261281
$bucket
262282
~~~~~~~
263283

0 commit comments

Comments
 (0)