RethinkDB 嵌套分组

RethinkDB nested grouping

我有一个 RethinkDB table,其中的文档看起来像这样:

[
  { "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" }
  (...)
]

我正在尝试编写一个查询,以便按 month/year 对我的数据进行分组,然后(在每个组内)按类别,然后对子组执行一些聚合。

根据 ReQL 文档 (https://www.rethinkdb.com/api/javascript/group/) 中给出的示例,这给出了第一步:

r.table("seances").group([r.row("date").month(), r.row("date").year()])

我被困在这里了。使用 group(r.row("category")) 链接会给出一条错误消息(无法在 group 的输出上调用 group)。在第二个 group 之前调用 ungroup 也不起作用。

知道怎么做吗? (ReQL 看起来很强大,但和我习惯的 lodash 大不相同...)

你可以写sequence.group(FIRST_GROUPING).ungroup().merge(function(row) { return {reduction: row('reduction').group(SECOND_GROUPING).ungroup()}; }).