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
- Host: GitHub
- URL: https://github.com/thesebas/php-mongodb-helpers
- Owner: thesebas
- License: mit
- Created: 2017-03-14T10:17:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-23T09:36:36.000Z (almost 8 years ago)
- Last Synced: 2025-08-13T12:40:08.269Z (10 months ago)
- Topics: mongodb, php, query-builder
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# php-mongodb-helpers
MongoDB php helpers to build queries.  [](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]
]
]]
]]
]);
```