通过uid创建索引

This commit is contained in:
meixiongfeng 2022-08-24 19:09:05 +08:00
parent 43ff5abd83
commit 4e75419f38
2 changed files with 12 additions and 2 deletions

View File

@ -11,6 +11,8 @@ import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelGourmet struct {
@ -22,7 +24,10 @@ func (this *modelGourmet) Init(service core.IService, module core.IModule, comp
this.TableName = string(comm.TableGourmet)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Gourmet)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}

View File

@ -11,6 +11,8 @@ import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelSmithy struct {
@ -22,7 +24,10 @@ func (this *modelSmithy) Init(service core.IService, module core.IModule, comp c
this.TableName = string(comm.TableSmithy)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Smithy)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}