From the course: MongoDB Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Solution: Write aggregation pipelines - MongoDB Tutorial
From the course: MongoDB Essential Training
Solution: Write aggregation pipelines
(upbeat instrumental music) - [Instructor] Okay, to answer this question we are going to perform an aggregation query on the movies collection. We are going to pass an array to the aggregate method with multiple stages inside. The first stage is going to be a project stage, and in the project stage we're going to project away all fields we don't need. And we are going to change the release year to only be the year. So, to change the release year field to only be the year we are going to use the year operator. We did not explicitly cover this operator in the course, but I hope you found it in the documentation. Okay, aside from the release year we are also going to retain the genre field, the runtime field, and the title field. Okay, let's try this for now just to make sure it works. That seems to work as expected. Okay, so let's add the second stage to this. In the second stage we are going to perform a match. And we're…
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
-
-
-
-