fix pipeline

This commit is contained in:
pasha1coil 2023-11-22 21:07:18 +03:00 committed by skeris
parent c149d6a743
commit ae5e06be33

@ -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 <GetRecentTariffs> of <HistoryRepository>",
zap.String("userId", userID),