Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ func UploadData[T any](client *mongo.Client, ctx context.Context, fptr *os.File,

// MongoDB aggregation run only when sections changes, instead of as a view where it's run for each query
func buildEvents(client *mongo.Client, ctx context.Context) {
sections := getCollection(client, "sections")

pipeline := mongo.Pipeline{
//separate each meeting
{{Key: "$unwind", Value: "$meetings"}},
Expand Down Expand Up @@ -311,15 +309,28 @@ func buildEvents(client *mongo.Client, ctx context.Context) {
}},
{Key: "buildings", Value: 1},
}}},
//set as events collection
{{Key: "$out", Value: "events"}},
}

sections := getCollection(client, "sections")
cursor, err := sections.Aggregate(ctx, pipeline)
if err != nil {
log.Panic(err)
}
defer cursor.Close(ctx)

events := getCollection(client, "events")
var results []interface{}
if err := cursor.All(ctx, &results); err != nil {
log.Panic(err)
}

if len(results) > 0 {
events.DeleteMany(ctx, bson.D{})
_, err = events.InsertMany(ctx, results)
if err != nil {
log.Panic(err)
}
}

log.Println("Done aggregating events!")
}