From e6323e1635fc66a491a1fe8492ffd8be4c0aa2cd Mon Sep 17 00:00:00 2001 From: zhx Date: Wed, 27 May 2026 14:48:24 +0800 Subject: [PATCH] Fix Mongo gift aggregate decoding --- internal/storage/gift_mongo.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/storage/gift_mongo.go b/internal/storage/gift_mongo.go index 34dc04b..764b5bd 100644 --- a/internal/storage/gift_mongo.go +++ b/internal/storage/gift_mongo.go @@ -55,6 +55,12 @@ func (r *MySQLRepository) listMongoGiftAmounts(ctx context.Context, db *mongo.Da {Key: "_id", Value: bson.D{{Key: "userId", Value: "$userId"}, {Key: "day", Value: "$day"}}}, {Key: "amount", Value: bson.D{{Key: "$sum", Value: "$amount"}}}, }}}, + bson.D{{Key: "$project", Value: bson.D{ + {Key: "_id", Value: 0}, + {Key: "userId", Value: "$_id.userId"}, + {Key: "day", Value: "$_id.day"}, + {Key: "amount", Value: "$amount"}, + }}}, ) cursor, err := db.Collection(giftRunningWaterCollection).Aggregate(ctx, pipeline) if err != nil { @@ -67,9 +73,8 @@ func (r *MySQLRepository) listMongoGiftAmounts(ctx context.Context, db *mongo.Da if err := cursor.Decode(&doc); err != nil { return nil, err } - idDoc, _ := doc["_id"].(bson.M) - userID := bsonInt64(idDoc["userId"]) - day := strings.TrimSpace(fmt.Sprint(idDoc["day"])) + userID := bsonInt64(doc["userId"]) + day := strings.TrimSpace(fmt.Sprint(doc["day"])) amount := bsonDecimal(doc["amount"]) if userID == 0 || day == "" { continue