thesebas/php-mongodb-helpers

There is no license information available for the latest version (v0.0.4) of this package.

MongoDB php helpers to build queries

v0.0.4 2017-08-29 22:21 UTC

This package is auto-updated.

Last update: 2024-04-25 09:22:38 UTC


README

MongoDB php helpers to build queries. BUILD STATUS Coverage Status

Write this:

$collection->aggregate([

  project([
      'field' => reduce(
          filter(
              path(...$arrayField),
              'tmp',
              eq(variable("tmp", ...$filterField), $filterValue)
          ),
          0,
          add(variable('value'), variable("this", $sumField))
      )
  ])

]);

instead of this:

$collection->aggregate([
  ['$project' => [
      'field' => ['$reduce' => [
          'input' => ['$filter' => [
              'input' => '$' . join('.', $arrayField),
              'as' => 'tmp',
              'cond' => ['$eq' => ["\$\$tmp." . join('.', $filterField), $filterValue]]
          ]],
          'initialValue' => 0,
          'in' => [
              '$add' => ['$$value', '$$this.' . $sumField]
          ]
      ]]
  ]]
]);