From the course: MongoDB Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
$group - MongoDB Tutorial
From the course: MongoDB Essential Training
$group
- [Instructor] Grouping data is a common pattern we need when accessing or manipulating data. Let's look at this in the terminal. In MongoDB, you can group data by using the $group stage in an aggregation pipeline. For this example, we are going to be using our sample data. In particular we are going to be using the inventory collection so let's just remind ourselves of what that looks like. Okay, let's test out the $group operator. First I'm going to specify the collection on which we're going to perform the aggregation and then I'm going to call the aggregate method. The aggregate method always takes an array of stages as input. Each stage is inside a document, so that's where we start. And then we're just going to specify the $group operator, which also takes a document as its value. Inside the document, you have to specify an ID. The ID is the thing by which the data is going to be grouped. In our case, I'm…
Contents
-
-
-
-
-
-
-
An overview of stages1m 47s
-
(Locked)
$group4m 14s
-
(Locked)
$bucket5m 15s
-
(Locked)
$unwind3m 18s
-
(Locked)
$merge and $out3m 59s
-
(Locked)
$function3m 27s
-
(Locked)
$lookup4m 44s
-
(Locked)
Performance10m 38s
-
(Locked)
Challenge: Write aggregation pipelines24s
-
(Locked)
Solution: Write aggregation pipelines5m 18s
-
-
-
-