Skip to content

Commit

Permalink
add index to label collection
Browse files Browse the repository at this point in the history
Signed-off-by: Min Min <[email protected]>
  • Loading branch information
jamsman94 committed Nov 1, 2024
1 parent 8171a41 commit 52192ad
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/microservice/aslan/core/common/repository/mongodb/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

type LabelColl struct {
Expand All @@ -47,8 +48,15 @@ func (c *LabelColl) GetCollectionName() string {
}

func (c *LabelColl) EnsureIndex(ctx context.Context) error {
// currently no query is required for the label defining collection
return nil
mod := mongo.IndexModel{
Keys: bson.D{
bson.E{Key: "key", Value: 1},
},
Options: options.Index().SetUnique(true),
}

_, err := c.Indexes().CreateOne(ctx, mod)
return err
}

func (c *LabelColl) Create(args *models.Label) error {
Expand Down

0 comments on commit 52192ad

Please sign in to comment.