Reputation: 466
Is there a way to push root documents to specific field on $facet
without $group
? For example,
db.artwork.aggregate( [
{
$facet: {
"categorizedByTags": [
{ $unwind: "$tags" },
{ $sortByCount: "$tags" }
],
"items": [{$push: "$$ROOT"}] // I want to push all root document to `items`.
}
}])
Upvotes: 1
Views: 1452
Reputation: 22276
Yes, just use an empty $match
, like so:
db.artwork.aggregate( [
{
$facet: {
"categorizedByTags": [
{ $unwind: "$tags" },
{ $sortByCount: "$tags" }
],
"items": [{$match: {}}]
}
}])
Upvotes: 2
Reputation: 185
You can use like this:
db.artwork.aggregate( [
{
$facet: {
items: [ { $match: {} } ],
}
}
])
Upvotes: 1