package mongo import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" ) // Will store the created collection object for a faster access var CollectionMap map[string]*mongo.Collection var IndexesMap map[string][]mongo.IndexModel func init() { CollectionMap = make(map[string]*mongo.Collection) IndexesMap = make(map[string][]mongo.IndexModel) IndexesMap["data"] = append(IndexesMap["data"], mongo.IndexModel{Keys: bson.D{ {Key: "description", Value: "text"}, {Key: "example", Value: "text"}}, }) IndexesMap["compute"] = append(IndexesMap["compute"], mongo.IndexModel{Keys: bson.D{ {Key: "description", Value: "text"}, {Key: "example", Value: "text"}, {Key: "owner", Value: "text"}}, }) IndexesMap["storage"] = append(IndexesMap["storage"], mongo.IndexModel{Keys: bson.D{ {Key: "description", Value: "text"}, {Key: "example", Value: "text"}}, }) IndexesMap["processing"] = append(IndexesMap["processing"], mongo.IndexModel{Keys: bson.D{ {Key: "description", Value: "text"}, {Key: "example", Value: "text"}, {Key: "owner", Value: "text"}, }, }) IndexesMap["workflow"] = append(IndexesMap["workflow"], mongo.IndexModel{Keys: bson.D{ {Key: "description", Value: "text"}, {Key: "example", Value: "text"}, {Key: "owner", Value: "text"}, }, }) } func GetObjIDFromString(id string) interface{} { objectID, err := primitive.ObjectIDFromHex(id) if err == nil { return objectID } return id }