Use query to filter by keys when grouping

Rather than filtering out results that have null values for keys
after the group handle it in the condition. This let's Mongo do the hard
work so we don't have to.

I completely forgot about this when I merged the pull request earlier.