Complete the code to add a new field 'totalPrice' by multiplying 'price' and 'quantity'.
db.orders.aggregate([{ $addFields: { totalPrice: { $multiply: ["$price", [1]] } } }])In MongoDB aggregation, to refer to a field, prefix it with '$'. So to multiply 'price' and 'quantity', use "$quantity".
Complete the code to add a field 'fullName' by concatenating 'firstName' and 'lastName' with a space.
db.users.aggregate([{ $addFields: { fullName: { $concat: ["$firstName", [1], "$lastName"] } } }])To join first and last names with a space, use a space string " " inside $concat.
Fix the error in the code to add a field 'discountedPrice' by subtracting 'discount' from 'price'.
db.sales.aggregate([{ $addFields: { discountedPrice: { $subtract: ["price", [1]] } } }])Field names in aggregation expressions must be prefixed with '$'. So use "$discount" to refer to the discount field.
Fill both blanks to add a field 'averageScore' by dividing 'totalScore' by 'numTests'.
db.students.aggregate([{ $addFields: { averageScore: { $divide: ["[1]", "[2]"] } } }])Use "$totalScore" and "$numTests" to refer to the fields inside the $divide operator.
Fill all three blanks to add a field 'summary' that concatenates uppercase 'category', a colon, and 'description'.
db.products.aggregate([{ $addFields: { summary: { $concat: [[1], [2], [3]] } } }])Use $toUpper to convert 'category' to uppercase, then add a colon and space string ": ", then add 'description'.