¿Hay alguna manera de enviar documentos raíz a un campo específico en $facet sin $group ? Por ejemplo,
db.artwork.aggregate( [ { $facet: { "categorizedByTags": [ { $unwind: "$tags" }, { $sortByCount: "$tags" } ], "items": [{$push: "$$ROOT"}] // I want to push all root document to `items`. } }])Sí, solo usa un $match vacío, así:
db.artwork.aggregate( [ { $facet: { "categorizedByTags": [ { $unwind: "$tags" }, { $sortByCount: "$tags" } ], "items": [{$match: {}}] } }])Puedes usar así:
db.artwork.aggregate( [ { $facet: { items: [ { $match: {} } ], } } ])