I am working on nestjs and I have a collection where 5 documents are saved and each document has a property name 'price'. I want to fetch price property from every document and need to sum up all and shows that sum as an output. How do I achieve this?
Asked
Active
Viewed 745 times
0
-
2It´s hard to guess what you really want to achieve without any line of code. Could you provide what you tried so far? Makes it so much easier for people to help you. – lstnrs May 19 '20 at 12:41
-
Does this answer your question? [MongoDb sum query](https://stackoverflow.com/questions/18969916/mongodb-sum-query) – whoami - fakeFaceTrueSoul May 19 '20 at 16:40
1 Answers
1
Use aggregate
.aggregate([
{
$group: {
_id: '',
sumPrices: { $sum: '$price' }
}
])

zishone
- 1,196
- 1
- 9
- 11