πŸ”₯Mongodb Aggregation Tutorial | Aggregation Functions in Mongodb | Mongodb Tutorial | Simplicode

SimpliCode
21 Nov 202218:24

Summary

TLDRThis tutorial by Simply Code delves into MongoDB's aggregation framework, essential for handling complex queries. It explains the fundamentals of aggregate queries, introduces key stages of the aggregation pipeline, and illustrates their application with examples. The video guides viewers on using match, group, sort, and project stages to process and analyze data, emphasizing the power of aggregation for pattern recognition and data insights in both SQL and NoSQL environments.

Takeaways

  • πŸ“š MongoDB Aggregation is used to perform complex operations on data, processing multiple documents and returning a single result.
  • πŸ” The 'match' stage in MongoDB's aggregation pipeline is similar to the 'WHERE' clause in SQL, filtering documents based on specified conditions.
  • πŸ‘₯ The 'group' stage groups documents with similar characteristics, akin to the 'GROUP BY' clause in SQL, allowing for operations like counting or summing values.
  • πŸ“ˆ The 'sort' stage orders the documents in the output, either in ascending or descending order, based on specified fields.
  • πŸ“Š The 'project' stage is used to include or exclude certain fields in the final output, shaping the result set to include only necessary data.
  • πŸ”’ Aggregation operations in MongoDB include sum, average, min, max, and push, which can be used to perform calculations and manipulate array data.
  • πŸ“ The script provided a practical example of using the aggregation pipeline with stages like match, group, and sort to perform operations on a collection of documents.
  • πŸ“‰ The 'count' operation within the aggregation pipeline can be used to determine the number of documents that meet certain criteria, such as belonging to a specific department.
  • πŸ› οΈ Aggregation is essential for analyzing unstructured data in MongoDB, as the data model can change over time with new entries.
  • πŸ“ˆ The tutorial demonstrated the use of MongoDB shell for executing aggregation operations and analyzing the results.
  • πŸ‘¨β€πŸ« The video tutorial aimed to educate viewers on the fundamentals of creating aggregate queries and using various expressions in MongoDB's aggregation framework.

Q & A

  • What is the primary purpose of MongoDB aggregation?

    -The primary purpose of MongoDB aggregation is to process data records in the database during an aggregation operation and return a single computed result. It groups multiple documents, applies an aggregation operation, and provides a single result.

  • How does MongoDB aggregation compare to SQL aggregation?

    -MongoDB aggregation is similar to SQL aggregation in that it allows for filtering, grouping, sorting, and reorganizing data to return documents in a collection, just like using the GROUP BY clause in SQL with operations like COUNT, AVG, MIN, and MAX for complex aggregations.

  • What are the main reasons for using aggregation in MongoDB?

    -Aggregation is used to gather data from different sources into a single outcome, process and analyze large amounts of nested data, perform complex operations on the data, and filter and sort documents to analyze data changes, especially important for unstructured data in MongoDB.

  • Can you explain the MongoDB aggregation pipeline stages?

    -The MongoDB aggregation pipeline stages include match, group, sort, and project. Match filters documents, group consolidates documents into groups, sort orders the documents, and project specifies the shape of the resulting documents.

  • How does the 'match' stage in the aggregation pipeline work?

    -The 'match' stage in the aggregation pipeline filters the input documents to pass only those documents that match the given condition to the next pipeline stage.

  • What is the 'group' stage in MongoDB aggregation used for?

    -The 'group' stage in MongoDB aggregation is used to group documents by the specified '_id' expression and can calculate aggregated values like sum, average, min, or max for each group.

  • What does the 'sort' stage in the aggregation pipeline do?

    -The 'sort' stage in the aggregation pipeline orders the input documents in ascending or descending order based on the specified fields.

  • What is the 'project' stage in MongoDB aggregation responsible for?

    -The 'project' stage in MongoDB aggregation is used to include, exclude, or add new fields to the documents and to reshape each document in the stream.

  • How can you perform a count operation using MongoDB aggregation to find the total number of employees in a department?

    -You can use the 'match' stage to filter employees by department ID and then use the 'count' function in the aggregation pipeline to get the total number of employees in that department.

  • What are some of the main aggregation operations in MongoDB similar to SQL?

    -Some of the main aggregation operations in MongoDB similar to SQL include SUM, AVG (average), MIN, MAX, and an additional operation, PUSH, which is used to add values to an array in the associated document.

Outlines

00:00

πŸ“š Introduction to MongoDB Aggregation

This paragraph introduces the concept of MongoDB aggregation, explaining its necessity as queries become more complex. It emphasizes the aggregation pipeline's ability to perform complex operations on data, grouping documents, and returning a single computed result. The tutorial aims to cover the fundamentals of creating aggregate queries, using various expressions, and the stages of the aggregation pipeline with examples. It also encourages new viewers to subscribe to the channel for the latest tech content.

05:00

πŸ” Understanding Aggregation in MongoDB

The paragraph delves into the definition of aggregation in MongoDB, comparing it to SQL's 'GROUP BY' clause and explaining how it processes data records to return a single result. It discusses the use of aggregation for filtering, grouping, and sorting data, and highlights the importance of aggregation in analyzing data to find patterns or insights. The paragraph also touches on MongoDB's flexibility with data models and the need for aggregation to handle unstructured data effectively.

10:03

πŸ› οΈ Aggregation Pipeline Stages in MongoDB

This section outlines the four main stages of the MongoDB aggregation pipeline: match, group, sort, and project. It describes how these stages work together to perform aggregation operations. The match stage is used to filter documents, group to collect related data, sort to order the data, and project to shape the output. An example using a collection named 'orders' illustrates how these stages can be applied to perform an aggregation operation, including grouping by customer ID and summing amounts.

15:06

πŸ“ˆ Aggregation Operations and MongoDB Shell Execution

The final paragraph discusses the main aggregation operations in MongoDB, such as sum, average, min, max, and push, which are analogous to SQL operations. It then transitions into a practical demonstration using the MongoDB shell, showing how to execute aggregation operations on a collection named 'employee'. The paragraph includes a step-by-step guide on writing queries for match and group stages, and how to count the total number of employees in specific departments, providing a hands-on understanding of MongoDB aggregation.

Mindmap

Keywords

πŸ’‘Aggregation

Aggregation in the context of databases refers to the process of combining data from multiple records into a single result. In the video, it is a key concept for understanding MongoDB's approach to handling complex queries. It is used to perform operations such as filtering, grouping, and reorganizing data. The script provides examples of how aggregation is used to simplify complex queries and retrieve summarized data from a collection of documents.

πŸ’‘MongoDB

MongoDB is a NoSQL database that is known for its document-oriented structure. The script discusses MongoDB's aggregation framework, which is used for processing and grouping data records to return a computed result. MongoDB's aggregation is highlighted as a powerful tool for data analysis, especially when dealing with unstructured data.

πŸ’‘Aggregation Pipeline

The Aggregation Pipeline is a concept in MongoDB that allows for a multi-stage processing of data. The script explains that it consists of stages like 'match', 'group', 'sort', and 'project', which are used to filter, group, order, and transform data, respectively. The pipeline is central to the video's tutorial on how to perform complex data operations in MongoDB.

πŸ’‘Match

In the context of the video, 'match' is an aggregation pipeline stage used to filter documents to pass into the next stage of the pipeline. It is compared to the 'WHERE' clause in SQL and is used to narrow down the dataset for further operations. The script demonstrates using 'match' to select documents with a specific status or department ID.

πŸ’‘Group

The 'group' stage in MongoDB's aggregation pipeline is used to group documents by specified fields, similar to the 'GROUP BY' clause in SQL. The video script illustrates how 'group' can be used to consolidate data based on common attributes, such as grouping employees by department ID and then performing calculations on the grouped data.

πŸ’‘Sort

'Sort' is an aggregation pipeline stage that orders the output documents. The script mentions that sorting can be done in ascending or descending order based on the field values. It is used to organize the data in a specific sequence, which is crucial for analysis and presentation.

πŸ’‘Project

The 'project' stage in MongoDB's aggregation pipeline is used to include or exclude certain fields from the output documents. The script explains that 'project' can be used to shape the result by removing unnecessary fields or adding computed fields, thus customizing the final output for specific needs.

πŸ’‘Sum

'Sum' is an aggregation operation that adds up values from documents in a collection. The video script uses 'sum' as an example of an operation that can be performed within the aggregation pipeline, such as calculating the total amount for orders or the total salary for employees in a department.

πŸ’‘Average

'Average' is another aggregation operation that computes the mean value of a set of numbers. In the script, 'average' is mentioned as a way to find the mean salary or other numerical values across a group of documents, providing an insight into central tendencies within the data.

πŸ’‘Minimum and Maximum

The 'minimum' and 'maximum' are aggregation operations that return the smallest and largest values from a collection, respectively. The script discusses these operations as part of the set of standard aggregation functions in MongoDB, which can be used to find extremes in data sets, such as the lowest or highest salaries.

πŸ’‘Push

'Push' is a MongoDB aggregation operation used to append values to an array. The script points out that since MongoDB is a NoSQL database, it often deals with arrays of elements, and 'push' is a way to add items to these arrays within the aggregation pipeline, which is a unique operation not typically found in SQL databases.

Highlights

Introduction to MongoDB aggregation concepts for complex queries.

Explanation of how MongoDB processes data records during an aggregation operation.

MongoDB's wide range of aggregation operations compared to relational databases.

The use of aggregation in MongoDB for filtering, grouping, sorting, and reorganizing data.

The SQL comparison with MongoDB's aggregation method, including group by clause and operations like count, average, min, and max.

Reasons for using aggregation: processing data from different sources to a single outcome.

Aggregation's role in handling nested data and performing complex operations.

The necessity of aggregation for analyzing data and finding patterns or information.

Aggregation's utility in dealing with the changing data model in MongoDB and analyzing unstructured data.

MongoDB's aggregation pipeline stages: match, group, sort, and project.

Detailed explanation of the match method in the aggregation pipeline.

The group method's functionality similar to SQL's group by clause.

How to use the sort method for ordering data in the aggregation pipeline.

The project method's role in removing unnecessary fields from the result.

An example of how aggregation works in MongoDB with a collection named 'orders'.

MongoDB shell demonstration of executing aggregation pipeline stages.

Using match, group, and count in an aggregation pipeline to find total employees in a department.

MongoDB aggregation operations: sum, average, min, max, and push.

End of session summary and invitation for further queries in the comments section.

Transcripts

play00:17

foreign

play00:22

[Music]

play00:23

I hope you guys are doing and staying

play00:25

safe welcome to yet another tutorial by

play00:27

simply code in today's session we'll be

play00:30

discussing about mongodb aggregation

play00:32

Concepts now when you first start

play00:34

working with mongodb you will most

play00:36

likely use the fine method or command

play00:38

for a variety of queries now however as

play00:41

your queries become more complex you

play00:43

will need to learn more about

play00:45

aggregation in mogodb which is used to

play00:47

perform various complex operations so in

play00:50

this tutorial we'll be covering the

play00:52

fundamentals of creating aggregate

play00:53

queries in mongodb and how to use

play00:55

various expressions in mongodb

play00:57

aggregation and furthermore we'll

play00:59

introduce the most important stages of

play01:01

aggregation pipeline along with examples

play01:04

of how to apply each one to this

play01:06

pipeline stages but before we begin if

play01:09

you're new to the channel and haven't

play01:10

subscribed already consider getting

play01:12

subscribed to our channel it's simply

play01:13

code to stay updated with all the latest

play01:15

tech content and hit that Bell icon to

play01:18

never miss an update from us so without

play01:20

any further Ado let's get started with

play01:22

today's topic

play01:24

all right firstly let us understand what

play01:26

is aggregation and mongodb mongodb

play01:29

process the data records in the database

play01:32

during an aggregation operation and

play01:34

returns a single computed result it

play01:36

actually groups multiple documents

play01:38

present in a collection applies an

play01:40

aggregation operation to it and then

play01:42

provides the user with a single result

play01:43

now mongodb offers a wide range of

play01:46

aggregation operations just like many

play01:48

other database systems in relational

play01:50

databases as well mongodb being a no SQL

play01:53

database also provides with the same

play01:55

functionality this enables you to filter

play01:58

data as you might with a query as well

play02:00

as grouping data sorting data into a

play02:03

particular order or reorganizing for

play02:06

returning the documents in the

play02:07

collection now this is just similar to

play02:10

the SQL wherein we use the group by

play02:11

clause in our aggregation function with

play02:14

the help of certain operations like

play02:16

count average some minimum and value to

play02:19

perform complex aggregation operations

play02:21

in the similar way mongodb aggregation

play02:24

is also similar to that of the SQL

play02:27

aggregation method that we follow

play02:30

so I hope you understood what is

play02:32

aggregation in mongodb Let Us Now

play02:34

understand why we use aggregation now

play02:36

data from different sources is gathered

play02:38

by an aggregation method which are then

play02:40

processed to a single outcome now to

play02:43

perform an aggregate function in a

play02:44

relational database the database

play02:46

management system typically extracts

play02:48

data from multiple rows of the same

play02:50

table but in a document oriented

play02:52

database like mongodb the database will

play02:55

gather information from various

play02:57

documents in the same collection so it

play02:59

basically group values from multiple

play03:00

documents together to a single resultant

play03:04

value now the next one is it fetches a

play03:07

lot of nested data to perform complex

play03:09

operations Now when using a database

play03:11

management system you must run an

play03:13

operation known as a query right each

play03:15

time you want to retrieve data from

play03:16

database however queries only return the

play03:19

information that is already present in

play03:20

the database you will frequently need to

play03:22

carry out another type of operation

play03:24

which is known as aggregation in order

play03:26

to analyze your data in order to find

play03:28

patterns or other information about the

play03:30

data so if there are if there is a

play03:32

complex operation that is needed for the

play03:35

data that is present in the documents

play03:37

you need aggregation and finally it

play03:39

filters and sort documents and analyze

play03:41

data changes now uh mongodb being an SQL

play03:45

nosql database the data model will

play03:48

frequently change as the data that is

play03:50

being you know inserting into the

play03:52

database might change over the time so

play03:55

in order to analyze this unstructured

play03:57

data it becomes quite important that you

play03:59

uh make a proper you know filtration and

play04:03

sorting of these documents to get a

play04:05

proper insights for your businesses and

play04:07

as well as your you know requirements so

play04:10

in that case aggregation can be quite

play04:12

useful which simplifies you know the

play04:14

complexity of the query that you have

play04:16

written and fetches the data in no time

play04:19

so these are some of the main reasons on

play04:21

why we use aggregation

play04:24

now aggregation uh in mongodb is

play04:26

performed using uh aggregation pipeline

play04:29

stages with consists of four different

play04:31

you know methods the first one is match

play04:34

next we have group Next we have sort and

play04:37

finally we have project these four

play04:39

combinedly are known as aggregation

play04:41

pipeline stages which perform

play04:43

aggregation as per the requirement now

play04:46

firstly when you take a collection and

play04:48

the first thing you need to is if you

play04:50

want to match only certain Fields you

play04:52

know within your documents to perform

play04:53

aggregation then you can use the match

play04:55

method next we have the group now just

play04:58

like the group by clause in SQL you can

play05:00

use the group uh you know function here

play05:02

as well in order to group all this

play05:04

similar or the related uh type of data

play05:07

in your

play05:08

you know uh present in your collections

play05:11

that is that the data that is present in

play05:14

your documents to in order to retrieve

play05:16

the similar kind of data you can use the

play05:18

group Next sort again sorting can be

play05:20

done in any other way like from

play05:21

ascending order or descending order next

play05:24

we have the project as we discussed

play05:26

earlier in a previous tutorial project

play05:27

is used to uh you know remove the

play05:30

unnecessary fields that you want in a

play05:32

result instead and finally after you

play05:35

know matching all the four uh pipeline

play05:37

stages then you get the resultant output

play05:40

so let us understand this uh with an

play05:42

example wherein we'll discuss how

play05:43

aggregation Works in mongodb now as

play05:45

discussed earlier the firstly the match

play05:47

condition uh you know specifies only the

play05:50

related documents that you want to

play05:52

consider so for example I have a

play05:54

collection name orders here and I'm

play05:56

performing uh you know an aggregation

play05:58

operation here so first I've mentioned

play06:00

the match for status a so I have like

play06:04

four documents here if you see any

play06:05

orders like for the four different

play06:07

customer IDs we have the amount and

play06:09

status now for I want to retrieve only

play06:11

uh those documents whose status is a so

play06:14

for that I'm using the match command

play06:16

here so match command only retrieve the

play06:19

one that you have specified here which

play06:20

is data say so we have only three

play06:22

records that have the status as field

play06:24

and their value is a so we have sorted

play06:28

initially with the match command next we

play06:30

want to group the values in the order of

play06:34

their let's say IDs and then so if you

play06:37

look at here we have two similar IDs

play06:39

which is A123 and b212 so what group

play06:42

does is it will match all the similar

play06:44

related fields together and produce a

play06:47

result so you can see the A123 and B21

play06:50

b212 are separated into a different

play06:52

groups and finally what I'm doing is I'm

play06:55

sorting I'm sorting and I'm applying an

play06:58

operation here with sum so what it does

play07:00

is it will basically calculate the total

play07:02

amount here so if you look at the first

play07:05

ID A123 the amount is 500 and 250. so

play07:08

the resultant output would be 750 and

play07:11

finally we have the customer ID of p212

play07:13

the amount is just 200. so in this way

play07:16

the aggregation pipeline Works in a

play07:18

methodology of wherein it matches the

play07:21

values that is the similar values from

play07:22

the documents then you can even group

play07:24

the data that you want to show in a

play07:27

resultant output and you can perform

play07:28

various operation uh using the aggregate

play07:31

functions like some minimum average with

play07:33

the help of sorting as well so this is

play07:36

basically how aggregation Works in mover

play07:37

DB so and finally as discussed earlier

play07:40

just like similar to SQL we have the

play07:42

same five or the main five aggregation

play07:46

operations in SQL which is the first one

play07:48

is sum it basically adds up the values

play07:50

of every documents of a collection next

play07:52

we have the average which computes the

play07:54

average value of every document of a

play07:56

collection next we have minimum or Min

play07:58

Returns the minimum of all values from

play08:00

the collection and next we have Max

play08:03

which is opposite to that of minimum

play08:04

minimum which Returns the maximum of all

play08:07

values from within the collection and

play08:09

finally we have an additional uh you

play08:11

know operation which is a push operation

play08:14

since mongodb is non or relational

play08:16

database we also work on the array of

play08:19

elements so in order to add the values

play08:20

to an array in the associated document

play08:22

within a collection you can use the push

play08:25

operation as well now this might be a

play08:28

bit confusing for you guys now so let us

play08:30

jump into mongodb shell for execution

play08:32

part where it will perform uh

play08:35

different operations using the

play08:37

aggregation pipeline stages and see how

play08:39

they are getting implemented and also

play08:41

perform a detailed analysis on the uh

play08:43

data The Collection that we have and we

play08:46

will bring out some inferences using the

play08:48

aggregation operations using various

play08:51

expressions like some average minimum

play08:53

and maximum so without any further delay

play08:55

let us jump into mongodbition so as you

play08:57

can see we have opened the mongodb shell

play08:59

command prompt line so let us just uh

play09:02

use the command show DBS to find out the

play09:05

database present so we have different

play09:07

databases like admin config local and

play09:09

simplified one values is simply code one

play09:11

as usual so use

play09:14

write the database name user B code one

play09:17

now let us see the collections that are

play09:19

present in the table so we have the

play09:22

employee collection again so let us

play09:24

write the command using the DB dot find

play09:27

DB dot collection name.find which is

play09:29

employee dot find

play09:31

so it will retrieve all the values that

play09:33

are present in this collection so we

play09:35

have our different fields like employee

play09:37

ID first name last name email phone

play09:39

number hiring date job ID salary manager

play09:42

ID and Department ID so all right let us

play09:46

now perform the aggregate operations in

play09:48

a sequential way firstly we look at the

play09:51

match aggregation you know stage where

play09:54

it will match the related fields that we

play09:56

want in a result then set now let's say

play09:58

if I want to match the department ID

play10:00

whose all the Embers who belong to the

play10:03

department added let's say 100 so in

play10:05

that case the following query would be

play10:06

DB Dot

play10:08

employee dot mention the aggregate

play10:11

keyword here which is a must otherwise

play10:13

it will throw an error when open the

play10:16

parenthesis and mention the square

play10:19

brackets and use the dollar symbol to

play10:22

write the statement for match

play10:29

put the column

play10:31

and open the parenthesis and mention the

play10:34

department ID

play10:37

field

play10:39

which is uh on which we are basically

play10:42

you know matching the attic watch so

play10:45

mentioned it again the colon and within

play10:49

single quotes mentioned the department

play10:50

ID name so since we have taken as 100

play10:52

I'm just taking it close the uh flower

play10:55

brackets

play10:56

two times and again mention the square

play10:58

bracket once again and close the

play11:00

parenthesis all right so this is the uh

play11:03

basically the query that we have written

play11:05

here which is DB dot imported Aggregate

play11:07

and we're using the match aggregation

play11:09

method here wherein we are matching all

play11:12

the records of the employees whose

play11:13

Department ID belongs to 100 so let's

play11:15

now enter

play11:16

uh I think there is an error here

play11:21

so we had a error in the syntax guys uh

play11:24

so as you can see in the output we can

play11:26

see only those records of the employees

play11:28

were in it is showing uh the records

play11:30

whose Department ID is hundred so we

play11:33

have the employee id108 109 110 111 and

play11:37

112 113 and all of them have their

play11:40

employee Department IDs sorry our

play11:43

department IDs 100. so I hope you

play11:46

understood this so let us now uh go

play11:49

through the next stage of aggregation

play11:50

Pipeline with valenvale group uh the

play11:53

values now so for that the following

play11:56

query would be DB dot employee

play11:59

dot aggregate

play12:02

which is the keyword again open the

play12:05

parenthesis

play12:08

and mention the double

play12:11

square brackets open the flower brackets

play12:14

and use the dollar symbol again write

play12:17

the group keyword

play12:20

and open the flower brackets again

play12:23

and mention the ID here so I'll explain

play12:26

why we are taking this here again

play12:29

so firstly let us just write the you

play12:31

know command and then I'll explain to

play12:33

you guys that why we are implementing

play12:35

that so I want to group all the

play12:38

basically the department IDs right so I

play12:40

am taking Department ID

play12:44

so mention the dollar symbol

play12:47

so the field name which is the

play12:49

department ID

play12:51

close the

play12:52

flower brackets twice mentioned are a

play12:56

double bracket square bracket as well

play13:02

so when you enter uh you can see the

play13:04

list of all the department IDs that are

play13:06

present in our collection so we have

play13:08

various I uh Department IDs like 60 10

play13:11

30 70 40 110 115 20 98 and so on

play13:18

so now you might have a doubt that why

play13:21

we are using the ID field layer now we

play13:23

are using the group stage to group the

play13:25

input documents by the specified you

play13:27

know ID expression which returns a

play13:29

single document containing the all the

play13:31

cumulative values of all the ER

play13:33

Department IDs that we have taken here

play13:35

so in this above example only the group

play13:37

stage is specified in the pipeline

play13:39

whereas the group uses the ID field to

play13:42

calculate at the value for all the input

play13:44

documents as a whole so the expression

play13:46

ID column uh the dollar symbol

play13:50

Department ID creates a distinct group

play13:52

on the field Department name since you

play13:54

don't uh we didn't calculate any

play13:56

accumulated values in our document it

play13:58

Returns the distinct values of

play14:00

Department IDs that are present in the

play14:02

table or in a document so in this way

play14:05

you can use the group aggregation method

play14:07

as well

play14:09

so this is how you can use the match and

play14:11

group stages wherein you can combine

play14:13

both these as well so next let us look

play14:15

at how to create an aggregation

play14:17

operation using one of the expression

play14:20

that we have like count average sum or

play14:22

minimum now let's say if I want to count

play14:24

the total employees in a particular

play14:25

Department in that case I'll basically

play14:27

use the match statement wherein it will

play14:30

group all the values of the employees

play14:33

whose Department IDs in a particular you

play14:35

know value and then it will count the

play14:38

total number of employees in that group

play14:40

so for that the following query would be

play14:42

DB Dot

play14:44

employee Dot

play14:46

aggregate

play14:48

open the

play14:54

open the brackets and uh

play14:57

square brackets as well and then mention

play14:59

the flower back brackets and then use

play15:01

the dollar match group stage

play15:06

wherein we are matching uh you know

play15:09

the department ID let's say Department

play15:11

ID of 60. so in that case it would be

play15:15

Department

play15:17

ID

play15:20

I have taken the value as 60 mentioned

play15:22

in the double quotes

play15:24

and close the brackets

play15:27

put a comma and then basically we are

play15:29

counting right so I'll use the count

play15:31

function here

play15:33

so put the dollar sign

play15:37

and check the count keyword

play15:40

and let's say

play15:42

the statement would be total

play15:45

employees

play15:47

in Department

play15:50

60.

play15:52

right so

play15:54

mention the put these close the uh

play15:57

brackets as well

play16:01

square brackets

play16:02

second

play16:07

so when you press the enter in a

play16:09

resultant output it states that total

play16:10

employees and Department 60 is 5. so

play16:13

similarly you can check for various

play16:15

other departments as well so let us just

play16:17

verify if it's showing correctly or not

play16:19

I'll just copy paste this and let's say

play16:22

for 100 now I want the total number of

play16:25

employees present in the department 100

play16:28

so in that case I'll just mention it

play16:30

I'll just change the values and let us

play16:33

now print enter so as you can see in the

play16:35

resultant set or result in the output

play16:37

you can see the total number of

play16:38

employees and Department hundred is six

play16:40

wherein we have the total number of

play16:43

employees in Department 60 is five so in

play16:45

this way you can use the various

play16:47

aggregation stages using the match group

play16:49

and as well as sort as well and perform

play16:53

various aggregation operations like Sim

play16:55

uh some minimum maximum as well

play16:59

so I think we have covered most of the

play17:02

concepts that we have discussed in our

play17:03

you know tutorial so that brings us to

play17:05

the end of today's session guys I hope

play17:07

you understood uh what aggregation

play17:09

methods and how they are used in mongodb

play17:12

thank you for watching the video guys if

play17:14

you found this tutorial informative and

play17:15

helpful give it a thumbs up and share it

play17:18

with your friends and colleagues if you

play17:20

have any further queries regarding any

play17:21

of the topics covered in today's session

play17:22

feel free to let us know in the comment

play17:24

section below and a team of experts will

play17:26

be more than happy to help resolve all

play17:27

your queries at the earliest until next

play17:29

time stay safe and keep coding

play17:33

foreign

play17:35

[Music]

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
MongoDBAggregationData AnalysisTutorialDatabaseNoSQLSQL ComparisonPipeline StagesData ProcessingTech Education