@@ -0,0 +1,57 @@
|
||||
package officialWebsitemod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type M = bson.M
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const (
|
||||
tableBasicData = "official_website_basic_data"
|
||||
tableHero = "official_website_hero"
|
||||
tableAlbum = "official_website_album"
|
||||
tableVideo = "official_website_video"
|
||||
tableTag = "official_website_tag"
|
||||
tableRecruitForm = "official_website_recruit_form"
|
||||
tableJobList = "official_website_job"
|
||||
tableNews = "official_website_news"
|
||||
tableNewsDetail = "official_website_news_detail"
|
||||
tablePartner = "official_website_partner"
|
||||
tableBusiness = "official_website_business"
|
||||
tablePhotograph = "official_website_photograph"
|
||||
)
|
||||
|
||||
func coll(t *db.MongoTool, tableName string) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(tableName)
|
||||
}
|
||||
return t.Coll(tableName)
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(tableBasicData)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
func initIndex() {
|
||||
// 需要 seoSlug 唯一标识的表:稀疏唯一索引(空值不参与唯一约束,配合 bson omitempty)
|
||||
seoSlugTables := []string{tableHero, tableAlbum, tableVideo, tablePhotograph, tableNews}
|
||||
for _, table := range seoSlugTables {
|
||||
if _, err := coll(nil, table).CreateIndex([]mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "seoSlug", Value: 1}},
|
||||
Options: options.Index().SetUnique(true).SetSparse(true),
|
||||
},
|
||||
}); err != nil {
|
||||
panic(fmt.Sprintf("officialWebsite seoSlug index err [%s] ==> [%+v]", table, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user