I would like to know if there is anyway I can "group by" my results with MongoDB/Php.
This is the code I'm using to display my rows:
$count = $col->find(array('order_id' => array('$gt' => '0')))->count();
I need to group them by order_id
.
Apparently, we cannot do a count()
on a group()
as find()
WORKS: $countfind = $col->find()->count();
DOESN'T WORK: $countgroup = $col->group($keys)->count();
I need to count this groupby please.
Thanks for your help.
The $group stage groups the documents by date and calculates the total sale amount, average quantity, and total count of the documents in each group. Third Stage: The $sort stage sorts the results by the total sale amount for each group in descending order.
Groups documents by some specified expression and outputs to the next stage a document for each distinct grouping. The output documents contain an _id field which contains the distinct group by key.
Group operator (also known as an accumulator operator) is a crucial operator in the MongoDB language, as it helps to perform various transformations of data. It is a part of aggregation in MongoDB. MongoDB is an open-source NoSQL database management program. NoSQL is an alternative to traditional relational databases.
Sometimes you may want to get an array of distinct values in a collection. You can accomplish this using the distinct() method:
$ages = $dm->createQueryBuilder('User')
->distinct('age')
->getQuery()
->execute();
http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/query-builder-api.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With