I have a RethinkDB table where documents look something like this:
[
{ "date": Mon Oct 05 2015 19:30:00 GMT+01:00, "category": 1, "name": "Alice" },
{ "date": Wed Oct 07 2015 14:00:00 GMT+01:00, "category": 2, "name": "Ben" },
{ "date": Mon Nov 16 2015 12:30:00 GMT+01:00, "category": 1, "name": "Charles" },
{ "date": Sun Nov 01 2015 22:15:00 GMT+01:00, "category": 1, "name": "Donald" }
(...)
]
I'm trying to write a query in order to group my data by month/year, then (within each group) by category, and then perform some aggregation on the subgroups.
Based on the example given in the ReQL docs (https://www.rethinkdb.com/api/javascript/group/), this gives the first step:
r.table("seances").group([r.row("date").month(), r.row("date").year()])
I'm stuck here. Chaining with group(r.row("category"))
gives an error message (Cannot call group
on the output of group
). Calling ungroup
before the second group
doesn't work either.
Any idea how it can be done? (ReQL looks very powerful but quite different from what I'm accustomed to with lodash...).
You can write sequence.group(FIRST_GROUPING).ungroup().merge(function(row) { return {reduction: row('reduction').group(SECOND_GROUPING).ungroup()}; })
.
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