diff --git a/modules/friend/model_friend.go b/modules/friend/model_friend.go index 30dec2f7d..f12b1c7cd 100644 --- a/modules/friend/model_friend.go +++ b/modules/friend/model_friend.go @@ -9,6 +9,7 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" + mgooptions "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -22,7 +23,8 @@ func (this *ModelFriend) Init(service core.IService, module core.IModule, comp c err = this.MCompModel.Init(service, module, comp, options) this.moduole = module.(*Friend) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ - Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + Options: mgooptions.Index().SetUnique(true), }) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "assistHeroId", Value: bsonx.Int32(1)}},