MongoDB Aggregation helper
This project is part of francetv zoom open source projects (iOS, Android and Angular)., (*1)
Class to help to build mongodb aggregation query., (*2)
Install
In composer.json, (*3)
"repositories": [
{
"type": "vcs",
"url": "git@github.com/francetv/mongodb-aggregation-helper.git"
}
]
And run composer, (*4)
composer require ftv/mongodb-aggregation-helper
How to use
Create a new instance of Ftv\MongoDB\Aggregation with an instance of \MongoCollection as parameter., (*5)
You can use method to build aggregation. There are chainable., (*6)
$aggregation = $this->createAggregate()
->addMatch([
'groupId' => 'group-id',
'publication.startDate' => ['$gte' => new \MongoDate() ],
])
->addSort([['field' => 'updated', "order" => 'desc']])
->addProject([
'slug' => 1,
'diff' => ['$subtract' => [new \MongoDate(), '$publication.startDate']]
]);
Then, execute it., (*7)
$aggregation->execute();