generated from PenaSide/GolangTemplate
fix pipeline
This commit is contained in:
parent
c149d6a743
commit
ae5e06be33
@ -117,19 +117,14 @@ func (receiver *HistoryRepository) GetRecentTariffs(ctx context.Context, userID
|
|||||||
ID string `bson:"tariffID"`
|
ID string `bson:"tariffID"`
|
||||||
}
|
}
|
||||||
filter := bson.D{
|
filter := bson.D{
|
||||||
{fields.History.UserID, userID},
|
{Key: fields.History.UserID, Value: userID},
|
||||||
{fields.History.IsDeleted, false},
|
{Key: fields.History.IsDeleted, Value: false},
|
||||||
}
|
}
|
||||||
pipeline := mongo.Pipeline{
|
findOptions := options.Find()
|
||||||
{{"$match", filter}},
|
findOptions.SetSort(bson.D{{"createdAt", -1}})
|
||||||
{{"$unwind", "$rawDetails"}},
|
findOptions.SetLimit(100)
|
||||||
{{"$match", bson.D{{"rawDetails.Key", "tariffs"}}}},
|
|
||||||
{{"$unwind", "$rawDetails.Value"}},
|
cursor, err := receiver.mongoDB.Find(ctx, filter, findOptions)
|
||||||
{{"$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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
receiver.logger.Error("failed to get recent tariffs on <GetRecentTariffs> of <HistoryRepository>",
|
receiver.logger.Error("failed to get recent tariffs on <GetRecentTariffs> of <HistoryRepository>",
|
||||||
zap.String("userId", userID),
|
zap.String("userId", userID),
|
||||||
|
Loading…
Reference in New Issue
Block a user