generated from PenaSide/GolangTemplate
fix: add unwind and group stages to recent tariffs obtaining
This commit is contained in:
parent
4f8963f8a3
commit
4a3cf4be25
@ -120,6 +120,18 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
|
||||
}},
|
||||
}
|
||||
|
||||
unwindStage := bson.D{
|
||||
{Key: "$unwind", Value: bson.D{
|
||||
{Key: "path", Value: "$rawDetails.tariffs"},
|
||||
}},
|
||||
}
|
||||
|
||||
groupStage := bson.D{
|
||||
{Key: "$group", Value: bson.D{
|
||||
{Key: "_id", Value: "$rawDetails.tariffs.id"},
|
||||
}},
|
||||
}
|
||||
|
||||
sortStage := bson.D{
|
||||
{Key: "$sort", Value: bson.D{
|
||||
{Key: "createdAt", Value: -1},
|
||||
@ -130,7 +142,7 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
|
||||
{Key: "$limit", Value: 100},
|
||||
}
|
||||
|
||||
cursor, err := receiver.mongoDB.Aggregate(ctx, mongo.Pipeline{matchStage, sortStage, limitStage})
|
||||
cursor, err := receiver.mongoDB.Aggregate(ctx, mongo.Pipeline{matchStage, unwindStage, sortStage, groupStage, limitStage})
|
||||
if err != nil {
|
||||
receiver.logger.Error("failed to get recent tariffs on <GetRecentTariffs> of <HistoryRepository>",
|
||||
zap.String("userId", userID),
|
||||
|
Loading…
Reference in New Issue
Block a user