diff --git a/internal/interface/repository/history.go b/internal/interface/repository/history.go index 073aacb..8aa73f6 100644 --- a/internal/interface/repository/history.go +++ b/internal/interface/repository/history.go @@ -117,19 +117,14 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID ID string `bson:"tariffID"` } filter := bson.D{ - {fields.History.UserID, userID}, - {fields.History.IsDeleted, false}, + {Key: fields.History.UserID, Value: userID}, + {Key: fields.History.IsDeleted, Value: false}, } - pipeline := mongo.Pipeline{ - {{"$match", filter}}, - {{"$unwind", "$rawDetails"}}, - {{"$match", bson.D{{"rawDetails.Key", "tariffs"}}}}, - {{"$unwind", "$rawDetails.Value"}}, - {{"$group", bson.D{{"_id", "$rawDetails.Value.Key.id"}}}}, - {{"$sort", bson.D{{"createdAt", -1}}}}, // -1 specifies descending order - {{"$limit", 100}}, - } - cursor, err := receiver.mongoDB.Aggregate(ctx, pipeline) + findOptions := options.Find() + findOptions.SetSort(bson.D{{"createdAt", -1}}) + findOptions.SetLimit(100) + + cursor, err := receiver.mongoDB.Find(ctx, filter, findOptions) if err != nil { receiver.logger.Error("failed to get recent tariffs on of ", zap.String("userId", userID),