ad-si
October 26, 2021, 8:49am
1
Currently most of our MongoDB queries start with a $lookup
and therefore the MongoDB node is quite useless to us without any support for aggregation pipelines.
One could use MongoDB Views to work around this problem, but the support for views is currently so bad in the MongoDB ecosystem (especially on MongoDB’s own Atlas) that we try to avoid it.
luizeof
November 18, 2021, 11:18pm
2
Just made this 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" } }
]
```
1 Like