The stats helper

The primary responsibility of the stats helper module is to gather some totals for our application. These stats are for things such as the total number of images uploaded, the total number of comments, the total views for all the images combined, and the total likes for all the images combined. Your first inclination might be to assume that we are going to query MongoDB for all the images and loop through every image to track all of the views and totals. That's one way to do it, but it's pretty inefficient. Fortunately, MongoDB has some built-in functionalities which make generating these kinds of values a snap.

As we are going to be making a number of calls to MongoDB, we are going to rely on the async.parallel function ...

Get Web Development with MongoDB and Node - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.