Could this be implemented as a recursive dictionary merge and then leave the laying out of the response to the next layer up? Something like
```python
def recursive_merge(out, keys, values):
	if not len(keys):
		return values
	key = values.pop(keys[0])
	if key not in out:
		out[key] = {}
	out[key].update(recursive_merge(out[key], keys[1:], values))
	return out

keys = ['_week_start_at', 'myOtherGrouping']
output = {}
mongo_result = # whatever it is
for result in mongo_result:
  output = recursive_merge(output, keys, result)
```

Then in the next layer up
```python
if key[0] == '_week_start_at':
  results = []
  for _week_start_at, value in sorted(output.items()):
    results.append({
      "_start_at": _week_start_at,
      "_end_at": _week_start_at + timedelta(days=7),
     keys[1]: value
    })
```
We get a couple of benefits this way; we can easily extend to further levels of grouping, we can use the same method for single and multi-level grouping and we leave a lot more of the details about how the response is formatted until later.

Sorry for the epic comment, I couldn't think of a way of describing it without code.