Skip to content

Commit 971d735

Browse files
committed
[API] feat: use options for upsert
1 parent c2abb54 commit 971d735

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

API/pkg/repository/stats_repository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ArmchairDevelopers/Kyber/API/pkg/models"
99
"go.mongodb.org/mongo-driver/v2/bson"
1010
"go.mongodb.org/mongo-driver/v2/mongo"
11+
"go.mongodb.org/mongo-driver/v2/mongo/options"
1112
)
1213

1314
type StatsRepository interface {
@@ -52,7 +53,7 @@ func (r *mongoStatsRepo) Upsert(ctx context.Context, ownerID string, userID stri
5253
}
5354

5455
id := r.getDBKey(ownerID, userID, source)
55-
_, err := r.col.UpdateOne(ctx, bson.M{"_id": id}, bson.M{"$set": model}, bson.D{{Key: "upsert", Value: true}})
56+
_, err := r.col.UpdateOne(ctx, bson.M{"_id": id}, bson.M{"$set": model}, options.UpdateOne().SetUpsert(true))
5657

5758
return err
5859
}

0 commit comments

Comments
 (0)