Aggregation Process in MongoDB

A free video tutorial from Bogdan Stashchuk | Software Engineer, MBA, PhD
Just keep learning - stashchuk
Rating: 4.7 out of 5Instructor rating
23 courses
267,256 students
LECTURE - Aggregation Process

Learn more from the full course

Complete MongoDB Administration Guide

Master MongoDB database using JavaScript Mongo Shell, Robo 3T (Robomongo) and MongoDB Compass

10:15:02 of on-demand video • Updated March 2023

Deeply understand how MongoDB works - cursor, batch size, iterator
Launch production database on the Atlas MongoDB - managed cloud-based MongoDB database
Install and configure production MongoDB on the dedicated or virtual private server
Understand and use different MongoDB BSON types - ObjectId, ISODate, NumberInt etc.
Learn how to use MongoDB Shell, Robo 3T (Robomongo), MongoDB Compass for database management
Perform different kinds of update operations using operators $set, $rename, $addToSet, $push, $inc etc
Use different kinds of queries and query operators like $in, $eq, $regex, $elemMatch etc.
Easily combine different aggregation stages like $match, $group, $unwind
Understand purpose of the indexes and create indexes
Use backup and restore tools - mongoexport, mongoimport, mongodump and mongorestore
Let's first look at an aggregation process. We will not dire too deeply in details now, just high-level overview. Let's suppose at the beginning we have some documents in the collection. So entire collection is here. First we can perform Match operation like we did in "find()" or "update()" methods. This match query can produce subset of the documents. Then you can take this subset of the documents and perform group operation. As a result of the group operation you will get brand new documents. You can group matched documents based on certain condition. For example by age, by score, by state, by country and so on. And as a result of operation you will get new documents and each document will represent each group. For example each country, for example we have collection of persons. We can match persons that live for example just in USA and then group by state and in the results we will get documents, each document will represent certain state and each document will contain quantity of the persons that live in certain state. So aggregation is looks like a pipe. So we have large set of documents, then we make it smaller and smaller and at the end we will get some groups of those documents. Again this is a high level and later in the course we will dire in deeper details. Let's go on and next talk about aggregate() method and about its syntax. See in a second.