Grokking MongoDB
0% completed
Updates with Aggregation Pipeline
A fruit shop needs to raise every price by 10 percent and store a total on each order. The $mul update operator can raise the price, but the total depends on two fields of the same document, and no update operator can calculate a value from two fields. This job needs an update pipeline. This lesson shows that method, and then the $merge stage, which writes the results of a normal aggregation to a collection, as $out does, but without replacing the whole collection.
Here are the orders, with a price on each one.
db.orders.drop() db.orders.insertMany([
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%