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.
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()])
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