Complete the code to use $facet to run multiple pipelines in one aggregation.
db.collection.aggregate([{ $facet: { results: [[1]] } }])The $facet stage requires an array of pipeline stages. Here, we start with a $match stage inside the 'results' pipeline.
Complete the code to add a second pipeline named 'counts' inside $facet.
db.collection.aggregate([{ $facet: { results: [{ $match: { status: 'A' } }], counts: [[1]] } }])The $count stage counts the number of documents passing through the pipeline and outputs a document with the count.
Fix the error in the $facet stage by completing the missing pipeline for 'averageScore'.
db.collection.aggregate([{ $facet: { averageScore: [[1]] } }])The $group stage with $avg accumulator calculates the average score across documents.
Fill both blanks to create two pipelines inside $facet: one for filtering active users and one for counting them.
db.users.aggregate([{ $facet: { activeUsers: [[1]], activeCount: [[2]] } }])The first pipeline filters active users with $match. The second pipeline counts them with $count.
Fill all three blanks to create pipelines inside $facet: one to sort by age, one to group by city, and one to count total documents.
db.people.aggregate([{ $facet: { sortedByAge: [[1]], groupedByCity: [[2]], totalCount: [[3]] } }])The first pipeline sorts documents by age ascending. The second groups documents by city. The third counts total documents.