I have a document:
{"price1": 500, "price2": 500}
I want to find all documents where "(price1 + price 2) < 1200". I assume I can do this by using the aggregation framework, but not seeing the correct way.
You can do it using $add. Try the following code:
db.collection.aggregate([
{ $project: { total: { $add: [ "$price1", "$price2" ] } } },
{ $match: {total: {$lt: 1200 }} }
])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With