An open API service indexing awesome lists of open source software.

https://github.com/thesebas/php-mongodb-helpers

MongoDB php helpers to build queries
https://github.com/thesebas/php-mongodb-helpers

mongodb php query-builder

Last synced: 5 months ago
JSON representation

MongoDB php helpers to build queries

Awesome Lists containing this project

README

          

# php-mongodb-helpers
MongoDB php helpers to build queries. ![BUILD STATUS](https://api.travis-ci.org/thesebas/php-mongodb-helpers.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/thesebas/php-mongodb-helpers/badge.svg)](https://coveralls.io/github/thesebas/php-mongodb-helpers)

Write this:
```php
$collection->aggregate([

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

]);
```

instead of this:
```php
$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]
]
]]
]]
]);
```