|
| 1 | +package pipelines |
| 2 | + |
| 3 | +import ( |
| 4 | + "go.mongodb.org/mongo-driver/bson" |
| 5 | + "go.mongodb.org/mongo-driver/mongo" |
| 6 | +) |
| 7 | + |
| 8 | +var TrendsCourseProfSectionsPipeline = mongo.Pipeline{ |
| 9 | + |
| 10 | + bson.D{ |
| 11 | + {Key: "$lookup", |
| 12 | + Value: bson.D{ |
| 13 | + {Key: "from", Value: "sections"}, |
| 14 | + {Key: "localField", Value: "sections"}, |
| 15 | + {Key: "foreignField", Value: "_id"}, |
| 16 | + {Key: "as", Value: "sections"}, |
| 17 | + }, |
| 18 | + }, |
| 19 | + }, |
| 20 | + bson.D{ |
| 21 | + {Key: "$group", |
| 22 | + Value: bson.D{ |
| 23 | + {Key: "subject_prefix", Value: 1}, |
| 24 | + {Key: "course_number", Value: 1}, |
| 25 | + {Key: "sections", Value: 1}, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + |
| 30 | + bson.D{ |
| 31 | + {Key: "$unwind", |
| 32 | + Value: bson.D{ |
| 33 | + {Key: "path", Value: "$sections"}, |
| 34 | + {Key: "preserveNullAndEmptyArrays", Value: false}, |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + bson.D{ |
| 39 | + {Key: "$lookup", |
| 40 | + Value: bson.D{ |
| 41 | + {Key: "from", Value: "professors"}, |
| 42 | + {Key: "localField", Value: "sections.professors"}, |
| 43 | + {Key: "foreignField", Value: "_id"}, |
| 44 | + {Key: "as", Value: "professors"}, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + bson.D{ |
| 49 | + {Key: "$unwind", |
| 50 | + Value: bson.D{ |
| 51 | + {Key: "path", Value: "$sections"}, |
| 52 | + {Key: "preserveNullAndEmptyArrays", Value: false}, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + |
| 57 | + bson.D{ |
| 58 | + {Key: "$group", |
| 59 | + Value: bson.D{ |
| 60 | + {Key: "_id", |
| 61 | + Value: bson.D{ |
| 62 | + {Key: "$concat", |
| 63 | + Value: bson.A{ |
| 64 | + "$subject_prefix", |
| 65 | + "$course_number", |
| 66 | + "$professors.first_name", |
| 67 | + "$professors.last_name", |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + {Key: "sections", Value: bson.D{{Key: "$addToSet", Value: "$sections"}}}, |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | +} |
0 commit comments