Fix Mongo gift aggregate decoding

This commit is contained in:
zhx 2026-05-27 14:48:24 +08:00
parent 071daba7a5
commit e6323e1635

View File

@ -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