bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

Add MongoDB Collation, Aggregation, and update/insertMany operations #1196

Open bchamberlain-forbes opened 4 years ago

bchamberlain-forbes commented 4 years ago

I built out these modifications because we needed to use MongoDB Aggregations for dealing with complex data and utilize Collations for more efficient searching. Our models extend the Mapper class and use Aggregation as a standalone helper.

Aggregations can be built via distinct steps such as:

use DB\Mongo\Aggregation;

$agg = new Aggregation; $agg->match(["name" => "test]) ->lookup('otherCollection', 'other', 'collectionId', 'others') ->unwind('$others');

$model = new StartingDataModel(); $results = $model->aggregate($agg);

The formatting changes can likely be ignored, the existing formatting drives me crazy and is borderline unreadable ;)

pauljherring commented 4 years ago

The formatting changes can likely be ignored

IMHO...

Except they're drowning out the actual changes (I presume the majority of the 254/605 lines removed are such formatting - nearly half the changes .)

If you really want to overhaul the formatting, I'd suggest putting it in a separate PR, rather than doubling up on what the major thrust of this one is supposed to be.

But it's purely up to @ikkez of course...

ikkez commented 4 years ago

That's neat. Probably a useful feature to add support for the aggregation framework. Regarding the mapper adjustments, I'm just wondering if a magic __call that links to this->collection would be more appropriate than adding multiple simple methods that just copy the behaviour like findOneAndUpdate, updateMany and insertMany etc.