A kind of map/reduce using CTE's

  • Wonder how this would look in MongoDB