From the course: MongoDB Aggregation Pipeline: Advanced Data Analysis and Manipulation
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Adding and removing data with aggregations - MongoDB Tutorial
From the course: MongoDB Aggregation Pipeline: Advanced Data Analysis and Manipulation
Adding and removing data with aggregations
- [Instructor] In this video, we'll learn more about how to add and remove fields from our documents using the aggregation framework. For this lesson, we'll work out of the products collection in our database. Open up the products collection in MongoDB Compass and navigate to the Aggregations tab. The use case that we will solve for here is that we have a lot of inventory sitting around that we want to sell by offering a discount. The discount amount will be based on how much the item costs and we also don't want to send the quantity of items that we have to our application. It doesn't need to know it. To get started with writing this aggregation, we'll start off by writing a $match stage that is only going to return products that we have over 500 of in our warehouse. So we'll create the $match stage and we'll look at the quantity of items and make sure that we only get the ones that have more than or that are greater than…