From 59a53c7c734b300a167b41e6a5061668d684d224 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 21 Jun 2022 17:37:22 +0800 Subject: [PATCH] fix bug --- pkg/common/db/mongoModel.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/common/db/mongoModel.go b/pkg/common/db/mongoModel.go index 4576c26b5..7a4685b9e 100644 --- a/pkg/common/db/mongoModel.go +++ b/pkg/common/db/mongoModel.go @@ -984,12 +984,19 @@ func (d *DataBases) CreateSuperGroup(groupID string, initMemberIDList []string, Upsert: &upsert, } c = d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cUserToSuperGroup) - _, err = c.UpdateMany(sCtx, bson.M{"user_id": bson.M{"$in": initMemberIDList}}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts) - if err != nil { - session.AbortTransaction(ctx) - return utils.Wrap(err, "transaction failed") + //_, err = c.UpdateMany(sCtx, bson.M{"user_id": bson.M{"$in": initMemberIDList}}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts) + //if err != nil { + // session.AbortTransaction(ctx) + // return utils.Wrap(err, "transaction failed") + //} + for _, userID := range initMemberIDList { + _, err = c.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts) + if err != nil { + session.AbortTransaction(ctx) + return utils.Wrap(err, "transaction failed") + } + } - session.CommitTransaction(ctx) return err }