From 8963d3ba9bea3d13fb6175bb0f230110e5d3a197 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Mon, 26 Feb 2024 16:43:32 +0800 Subject: [PATCH] fix: import the enough param --- pkg/common/db/unrelation/mongo.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/common/db/unrelation/mongo.go b/pkg/common/db/unrelation/mongo.go index 6db551295..8e2403b64 100644 --- a/pkg/common/db/unrelation/mongo.go +++ b/pkg/common/db/unrelation/mongo.go @@ -38,7 +38,8 @@ const ( ) type Mongo struct { - db *mongo.Client + db *mongo.Client + config *config.GlobalConfig } // NewMongo Initialize MongoDB connection. @@ -58,7 +59,7 @@ func NewMongo(config *config.GlobalConfig) (*Mongo, error) { if err = mongoClient.Ping(ctx, nil); err != nil { return nil, errs.Wrap(err, uri) } - return &Mongo{db: mongoClient}, nil + return &Mongo{db: mongoClient, config: config}, nil } if shouldRetry(err) { time.Sleep(time.Second) // exponential backoff could be implemented here @@ -135,7 +136,7 @@ func (m *Mongo) CreateMsgIndex() error { // createMongoIndex creates an index in a MongoDB collection. func (m *Mongo) createMongoIndex(collection string, isUnique bool, keys ...string) error { - db := m.GetDatabase().Collection(collection) + db := m.GetDatabase(m.config.Mongo.Database).Collection(collection) opts := options.CreateIndexes().SetMaxTime(10 * time.Second) indexView := db.Indexes()