Add index creation
This commit is contained in:
@@ -151,3 +151,25 @@ func RemoveOutdatedServices(cutoff time.Time) (count int64, err error) {
|
||||
count = res.DeletedCount
|
||||
return // Automatically returns names values
|
||||
}
|
||||
|
||||
// Creates indexes on the Timetable collection
|
||||
func CreateTimetableIndexes() error {
|
||||
coll := MongoClient.Database(DatabaseName).Collection(TimetableCollection)
|
||||
indexModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{
|
||||
"trainUid": 1,
|
||||
"stpIndicator": 1,
|
||||
"scheduleStartDate": 1,
|
||||
},
|
||||
Options: options.Index().SetName("delete_query"),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := coll.Indexes().CreateMany(context.Background(), indexModels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"git.fjla.uk/owlboard/go-types/pkg/database"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// Puts an array of Corpus Documents into the database
|
||||
@@ -53,3 +56,27 @@ func convertStationsToInterfaceSlice(stationsData *[]database.StationEntry) *[]i
|
||||
}
|
||||
return &interfaceSlice
|
||||
}
|
||||
|
||||
func CreateCorpusIndexes() error {
|
||||
coll := MongoClient.Database(DatabaseName).Collection(CorpusCollection)
|
||||
indexModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{
|
||||
"tiploc": 1,
|
||||
},
|
||||
Options: options.Index().SetName("tiploc"),
|
||||
},
|
||||
{
|
||||
Keys: bson.M{
|
||||
"3alpha": 1,
|
||||
},
|
||||
Options: options.Index().SetName("3alpha"),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := coll.Indexes().CreateMany(context.Background(), indexModels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user