diff --git a/api/pkg/s3/service.go b/api/pkg/s3/service.go index e538c48ed..9cc22b7f3 100644 --- a/api/pkg/s3/service.go +++ b/api/pkg/s3/service.go @@ -180,6 +180,10 @@ func (s *APIService) GetBackendIdFromTier(ctx context.Context, tierName string) response.WriteError(http.StatusInternalServerError, err) return "" } + + if len(res.Tiers[0].Backends) == 0 { + return "" + } backendId = res.Tiers[0].Backends[rand.Intn(len(res.Tiers[0].Backends))] return backendId diff --git a/backend/pkg/db/drivers/mongo/mongo.go b/backend/pkg/db/drivers/mongo/mongo.go index cc4ceb194..b171cfcdf 100644 --- a/backend/pkg/db/drivers/mongo/mongo.go +++ b/backend/pkg/db/drivers/mongo/mongo.go @@ -235,7 +235,7 @@ func (repo *mongoRepository) UpdateTier(ctx context.Context, tier *model.Tier) ( if err != nil { return nil, err } - _, err = session.Database(defaultDBName).Collection(defaultTierCollection).UpdateOne(ctx, m, tier) + _, err = session.Database(defaultDBName).Collection(defaultTierCollection).UpdateOne(ctx, m, bson.M{"$set": tier}) if err != nil { return nil, err } @@ -257,7 +257,7 @@ func (repo *mongoRepository) ListTiers(ctx context.Context, limit, offset int, q } log.Infof("ListTiers, limit=%d, offset=%d, m=%+v\n", limit, offset, m) - cur, err := session.Database(defaultDBName).Collection(defaultCollection).Find(ctx, m) + cur, err := session.Database(defaultDBName).Collection(defaultTierCollection).Find(ctx, m) if err != nil { return nil, err