From dcee679f48d2f1819056b266363f510d3b1b1bb4 Mon Sep 17 00:00:00 2001 From: AndrewZuo01 Date: Tue, 12 Dec 2023 14:58:59 +0800 Subject: [PATCH] update user command --- pkg/common/db/mgo/user.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go index e410a91d1..988c15193 100644 --- a/pkg/common/db/mgo/user.go +++ b/pkg/common/db/mgo/user.go @@ -111,14 +111,26 @@ func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int } func (u *UserMgo) GetUserCommands(ctx context.Context, userID string, Type int32) (map[string]user.CommandInfo, error) { collection := u.coll.Database().Collection("userCommands") - filter := bson.M{"userID": userID, "type": Type} - var result UserCommand - err := collection.FindOne(ctx, filter).Decode(&result) + + cursor, err := collection.Find(ctx, filter) if err != nil { return nil, err } - return result.Commands, nil + defer cursor.Close(ctx) + results := make(map[string]user.CommandInfo) + for cursor.Next(ctx) { + var result struct { + Key string `bson:"key"` + Value user.CommandInfo `bson:"value"` + } + err = cursor.Decode(&result) + if err != nil { + return nil, err + } + results[result.Key] = result.Value + } + return results, nil } func (u *UserMgo) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {