Fix aggregates so they work in db calls