Add support for MongoDB's average aggregation

This converts an AVG query into MongoDB's $avg aggregation.