package db import ( "context" nameDB "f1-game/internal/name/db" "fmt" clog "github.com/cherry-game/cherry/logger" "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/mongo" ) // ver00004 修复 Marchs type ver00004 struct { } // Version 手动自增,必需唯一 func (ver00004) Version() int32 { return 4 } func (ver00004) Enable() bool { return false } func (p ver00004) Execute() bool { playerCollection := dbComponent.Collection(nameDB.Table_Player) ctx := context.Background() pipeline := mongo.Pipeline{ {{Key: "$set", Value: bson.D{{Key: "Data.Map.Marchs", Value: "$Data.Map.Teams"}}}}, {{Key: "$unset", Value: bson.A{"Data.Map.Teams"}}}, } result, err := playerCollection.UpdateMany(ctx, bson.D{}, pipeline) if err != nil { clog.Errorf("[repairPlayerTable] err = %v", err) return false } clog.Infof("%s is ok. result = %v", p.Desc(), result.ModifiedCount) return true } func (p ver00004) Desc() string { return fmt.Sprintf("[migrator - %d] repair chapter init level", p.Version()) }