Using multiple aggregates (SUM, COUNT, AVG) in a RethinkDB query

With a RethinkDB query, you can’t do “count” and “sum” quite the same as you’d do in SQL. Since it uses a map-reduce style engine underneath, you set count to “1” on each of your rows and then add these up later: r.db(‘performance’) .table(‘query_timings’) .pluck(‘DbId’) .group(‘DbId’) .map(function(row) { return { DbId: row(‘DbId’), Duration: row(‘Duration’), count: …