public function inventario(\App\Document\Tecnico $tecnico, $value)
{
$builder = $this->createAggregationBuilder();
$builder
->hydrate(\App\Document\Inventario::class)
->match()
->field('tecnico')
->references($tecnico)
->field('tipo')
->equals($value)
->group()
->field('_id')
->expression('$material')
->field('subtotal')
->sum('$cantidad')
;
return $builder->execute();
}
$ value is the value that I want to condition for the case where q is 'cond1' add and when it is 'cond2' subtract for the subtotal.
With this I get the results of the past value (cond1 or cond2) but I can not do that simultaneous operation.