xyxie 1 жил өмнө
parent
commit
e7b0ff3739

+ 8 - 4
utils/mgodb/mgo_config.go

@@ -2,10 +2,14 @@ package mgodb
 
 import (
 	"context"
+	"eta/eta_forum_admin/utils"
 	"fmt"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/event"
 	"go.mongodb.org/mongo-driver/mongo"
 	"go.mongodb.org/mongo-driver/mongo/options"
 	"go.mongodb.org/mongo-driver/mongo/readpref"
+	"sync"
 	"time"
 )
 
@@ -38,7 +42,7 @@ func NewMgoClient(mgoConfig MgoConfig) *mongo.Client {
 		Password:      mgoConfig.Password,
 	}
 	clientOpts := options.Client().ApplyURI(mgoConfig.Url).SetAuth(credential)
-	/*startedCommands := sync.Map{} // map[int64]bson.Raw
+	startedCommands := sync.Map{} // map[int64]bson.Raw
 
 	cmdMonitor := &event.CommandMonitor{
 		Started: func(_ context.Context, evt *event.CommandStartedEvent) {
@@ -55,7 +59,7 @@ func NewMgoClient(mgoConfig MgoConfig) *mongo.Client {
 			if ok {
 				commands = v.(bson.Raw)
 			}
-			utils.MongoLog.Info("\n【MongoDB】[%.3fms] [%v] %v \n", float64(evt.Duration)/1e6, commands, evt.Reply)
+			utils.MongoLog.Info("\n【MongoDB】[%.3fms] [%v] \n", float64(evt.Duration)/1e6, commands)
 		},
 		Failed: func(_ context.Context, evt *event.CommandFailedEvent) {
 			//log.Printf("Command: %v Failure: %v\n",
@@ -69,11 +73,11 @@ func NewMgoClient(mgoConfig MgoConfig) *mongo.Client {
 			}
 			utils.MongoLog.Info("\n【MongoDB】[%.3fms] [%v] \n %v \n", float64(evt.Duration)/1e6, commands, evt.Failure)
 		},
-	}*/
+	}
 
 	// 创建options
 
-	//clientOpts.SetMonitor(cmdMonitor)
+	clientOpts.SetMonitor(cmdMonitor)
 
 	clientOpts.SetMinPoolSize(MinPoolSize)
 	clientOpts.SetMaxPoolSize(MaxPoolSize)