Stefan
June 15, 2021, 5:31pm
#1
Hi Team, is it possible to madeup the possibility to use aggregate function with the mongodb node ? This would be good to made the calculations on the database.
Thanks,
Stefan
Just made this post a feature request. Make sure you upvote it.
1 Like
luizeof
November 18, 2021, 11:17pm
#3
Just made a pull request:
n8n-io:master
← luizeof:mongodb-aggregation
opened 08:10PM - 18 Nov 21 UTC
Allows the use of Aggregation (https://docs.mongodb.com/manual/aggregation/).
…
> An aggregation pipeline consists of one or more stages that process documents:
> - Each stage performs an operation on the input documents. For example, a stage can filter documents, group documents, and calculate values.
> - The documents that are output from one stage are input to the next stage.
> - An aggregation pipeline can return results for groups of documents. For example, return the total, average, maximum, and minimum values.
## Example:
```js
[
{ $match: { status: "urgent" } },
{ $group: { _id: "$productName", sumQuantity: { $sum: "$quantity" } } }
]
```
On-Demand Materialized Views works fine, which makes the N8N a great view maintainer for reports:
```js
[
{ $match: { date: { $gte: startDate } } },
{ $group: { _id: { $dateToString: { format: "%Y-%m", date: "$date" } }, sales_quantity: { $sum: "$quantity"}, sales_amount: { $sum: "$amount" } } },
{ $merge: { into: "monthlybakesales", whenMatched: "replace" } }
]
```
4 Likes
Cannot wait for the merge to happen.
1 Like
Stefan
November 29, 2021, 6:01pm
#5
Yes, this feature would benice.
Nivb_6
April 21, 2022, 1:06pm
#6
Got released with [email protected]
1 Like