From c75e258f8166cc74ef0dd8f05bb17e1627e8a3ab Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 1 Nov 2022 17:41:08 +0800 Subject: [PATCH] test cron --- pkg/common/db/mongoModel.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/common/db/mongoModel.go b/pkg/common/db/mongoModel.go index 72462a898..28513f4a1 100644 --- a/pkg/common/db/mongoModel.go +++ b/pkg/common/db/mongoModel.go @@ -264,21 +264,20 @@ func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, er c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat) regex := fmt.Sprintf("^%s", ID) findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1}) - var msg UserChat + var msgs []UserChat cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts) if err != nil { return nil, utils.Wrap(err, "") } - err = cursor.Decode(&msg) + err = cursor.Decode(&msgs) if err != nil { return nil, utils.Wrap(err, fmt.Sprintf("cursor is %s", cursor.Current.String())) } - //if len(msgs) > 0 { - // return msgs[0], err - //} else { - // return nil, errors.New("get msg list failed") - //} - return &msg, nil + if len(msgs) > 0 { + return &msgs[0], err + } else { + return nil, errors.New("get msg list failed") + } } func (d *DataBases) DelMongoMsgs(IDList []string) error {