From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Write aggregation pipelines

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