MongoDB — Transactions & Advanced Aggregation ($facet & $merge)
Execute multi-faceted search queries with $facet and write aggregation output to collections using $merge.
1Multi-Faceted Search with $facet
$facet Parallel Processing
db.products.aggregate([
{
$facet: {
"categorizedCount": [{ $groupBy: { _id: "$category", count: { $sum: 1 } } }],
"topProducts": [{ $sort: { price: -1 } }, { $limit: 5 }]
}
}
]);