Aggregation functions

You can also use following aggregation functions with .fields method:

  • MAX
  • MIN
  • AVG
  • SUM
  • EVERY
  • COUNT

There is a special object that you need to use for aggregation:

{ fn: <AGG_FUNCTION>, col: <DATASET_FIELD> }

Example:


[..]
posts.select().fields({ fn: "MAX", col: "likes" });
[..]

For COUNT function you can provide asterisk (*) as a field name. Also you can combine field names with aggregation functions to get more complicated results:


[..]
posts.select().fields("date", "author", { fn: "COUNT", col: "*" });
[..]