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

MongoDB\Collection doesn't have group method.. #1162

Open yedemon opened 5 years ago

yedemon commented 5 years ago

I see this frame already uses new \MongoDB\Client to support new Mongodb drive on php7, however in db/mongo/mapper.php, when handling 'group', it uses "$this->collection->group" which doesn't exist in class MongoDB\Collection. What should i do?

ikkez commented 5 years ago

The Mongo mapper was only built and tested for the old legacy Mongo PECL extention and then patched for the newer MongoDB extention. The used collection->group method is existing right here: https://www.php.net/manual/de/mongocollection.group.php Though the newer MongoDB PHP lib and its MongoDB PECL ext are compatible with older one, the grouping feature has changed with newer versions and they now use the aggregate framework that takes care about grouping and such. You can either use an older PECL extention, or help us write a patch for the mongo mapper as it seems that is has not been used much in the past, sorry.

ref. https://docs.mongodb.com/php-library/current/reference/method/MongoDBCollection-aggregate/ https://docs.mongodb.com/php-library/current/tutorial/crud/#complex-queries-with-aggregation

yedemon commented 5 years ago

Many thanks.. after days study.. i've realized that "group" is mainly for old version mongo, and "aggregate" is for newer MongoDB.. But this "aggregate" thing is way too far for me to coding into proper functions. I've refered to many other frameworks, like think-orm, lavaral, but none-of-them resolve aggregate well.

I am using fatfree framework for 2 years, and it's quite to my taste. I feel honored to write something for it. But there is a question that confuses me. In lib/db/mongo.php that writes. "$this->db=(new \MongoDB\Client($dsn,$options?:[]))->$dbname;". Is this "\MongoDB\Client" comes from mongo-php-library(https://github.com/mongodb/mongo-php-library), which i think is not matched for "fatfree"?

Thanks again for replying.

                   Yours, sincerely
ikkez commented 5 years ago

yes it is... the mongo-php-library github repository is the newer next-gen lib that we should adapt to.. or rewrite it completely and use the low-level-api from https://www.php.net/manual/en/set.mongodb.php which probably becomes a lot of fun implementing it... great chance for creative minds ;)

yedemon commented 5 years ago

Okay... thanks.. i'll try..