|
|
|
@ -8,7 +8,6 @@ import (
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
|
|
|
"log"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
@ -45,7 +44,7 @@ func (m *Mongo) InitMongo() {
|
|
|
|
|
config.Config.Mongo.DBMaxPoolSize)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.Println(utils.GetFuncName(1), "start to init mongoDB:", uri)
|
|
|
|
|
fmt.Println(utils.GetFuncName(1), "start to init mongoDB:", uri)
|
|
|
|
|
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
|
|
|
|
if err != nil {
|
|
|
|
|
time.Sleep(time.Duration(30) * time.Second)
|
|
|
|
@ -57,6 +56,10 @@ func (m *Mongo) InitMongo() {
|
|
|
|
|
m.DB = mongoClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mongo) GetClient() *mongo.Client {
|
|
|
|
|
return m.DB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mongo) CreateTagIndex() {
|
|
|
|
|
if err := m.createMongoIndex(cSendLog, false, "send_id", "-send_time"); err != nil {
|
|
|
|
|
panic(err.Error() + " index create failed " + cSendLog + " send_id, -send_time")
|
|
|
|
@ -97,7 +100,7 @@ func (m *Mongo) CreateWorkMomentIndex() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Mongo) createMongoIndex(collection string, isUnique bool, keys ...string) error {
|
|
|
|
|
db := m.DB.Collection(collection)
|
|
|
|
|
db := m.DB.Database(config.Config.Mongo.DBDatabase).Collection(collection)
|
|
|
|
|
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
|
|
|
|
|
indexView := db.Indexes()
|
|
|
|
|
keysDoc := bsonx.Doc{}
|
|
|
|
|