From the course: Coding Exercises: Advanced MongoDB
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Find: Use $project to shape your output - MongoDB Tutorial
From the course: Coding Exercises: Advanced MongoDB
Find: Use $project to shape your output
(game music) - [Instructor] There's often a bit of disconnect between the actual shape of the data in your document and the data that your applications need to be returned. An application will likely want fewer fields than the entire document and may even have specific naming requirements to use for the fields in your documents that don't match your field names. This is where a projection comes into play. The project phase in a pipeline solves for this use case allowing you to choose the fields that exist in the resulting document set at the completion of the pipeline. If renaming a field or creating an additional field is also a requirement, you can use the add field stage to create that new field in your output. The requirement for this challenge is to use the aggregate method with both add fields and project to run the following query in the customer's collection. Return all customers shaping the output by only…
Contents
-
-
-
(Locked)
Find: Using aggregation pipeline to process documents1m 57s
-
(Locked)
Find: Aggregation with $group and $sort2m 5s
-
(Locked)
Find: Use $project to shape your output2m 4s
-
(Locked)
Find: Create calculated fields2m 40s
-
(Locked)
Aggregate: Custom logic with an accumulator5m 2s
-
(Locked)
Aggregate: Custom logic with a function2m 22s
-
(Locked)
-
-