My table has a timestamp
field, which is a standard RethinkDB date field.
Can I group rows by day / week / month using this timestamp field? Couldn't find any examples in the group() docs.
RethinkDB: Can I group by day / week / month?
Asked Answered
To group by month, day, or day of week individually:
r.table(...).group(r.row('timestamp').month())
r.table(...).group(r.row('timestamp').day())
r.table(...).group(r.row('timestamp').dayOfWeek())
Grouping by the week isn't as easy at the moment, because ReQL is currently missing a function to get the week number from a data (see https://github.com/rethinkdb/rethinkdb/issues/2055 ). You can probably work around that by using some custom JavaScript code through r.js()
. Please let me know if this is important for you, so I can look into it.
If you want to group by combinations of multiple things, e.g. day and month:
r.table(...).group([r.row('timestamp').month(), r.row('timestamp').day()])
© 2022 - 2024 — McMap. All rights reserved.