Add RemoveOutdatedServices
This commit is contained in:
@@ -138,3 +138,19 @@ func CreateCifEntries(schedules []database.Service) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Removes any schedules which ended before 'cutoff'
|
||||
func RemoveOutdatedServices(cutoff time.Time) (count int64, err error) {
|
||||
// Define filter
|
||||
filter := bson.M{"scheduleEndDate": bson.M{"$lt": cutoff}}
|
||||
|
||||
collection := MongoClient.Database(databaseName).Collection(timetableCollection)
|
||||
|
||||
res, err := collection.DeleteMany(context.Background(), filter)
|
||||
if err != nil {
|
||||
return // Automatically returns named values
|
||||
}
|
||||
|
||||
count = res.DeletedCount
|
||||
return // Automatically returns names values
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user