diff --git a/M121 - The MongoDB Aggregation Framework/Chapter 3 - Core Aggregation - Combining Information/Lab 3.3 - Using $lookup/Lab 3-3 Solution.js b/M121 - The MongoDB Aggregation Framework/Chapter 3 - Core Aggregation - Combining Information/Lab 3.3 - Using $lookup/Lab 3-3 Solution.js index 14c43a4..ddc2bdb 100644 --- a/M121 - The MongoDB Aggregation Framework/Chapter 3 - Core Aggregation - Combining Information/Lab 3.3 - Using $lookup/Lab 3-3 Solution.js +++ b/M121 - The MongoDB Aggregation Framework/Chapter 3 - Core Aggregation - Combining Information/Lab 3.3 - Using $lookup/Lab 3-3 Solution.js @@ -24,24 +24,33 @@ // Builds the pipeline. var pipeline = [ - { $unwind : "$airlines" }, - { $lookup: { - from: "air_routes", - localField: "airlines", - foreignField: "airline.name", - as: "routes" - } - }, - { $unwind : "$routes" }, - { $match : { "routes.airplane" : { $in : [ "747", "380" ] } } }, - { $group : { - "_id" : "$name", - "routes_count" : { $sum : 1 } - } - }, - { $sort : {"routes_count" : -1 } } + { + $match: { + airplane: /747|380/ + } + }, + { + $lookup: { + from: "air_alliances", + foreignField: "airlines", + localField: "airline.name", + as: "alliance" + } + }, + { + $unwind: "$alliance" + }, + { + $group: { + _id: "$alliance.name", + count: { $sum: 1 } + } + }, + { + $sort: { count: -1 } + } ]; // Prints the result. print("Result: "); -printjson(db.air_alliances.aggregate(pipeline).next();); \ No newline at end of file +printjson(db.air_routes.aggregate(pipeline).next());