diff --git a/dbs/mongo/mongo.go b/dbs/mongo/mongo.go index ccf13b1..c0ee4ad 100644 --- a/dbs/mongo/mongo.go +++ b/dbs/mongo/mongo.go @@ -44,8 +44,6 @@ func (m *MongoDB) Init(collections []string, config MongoConf) { ResourceMap = make(map[string]interface{}) m.Logger.Info().Msg("Connecting to" + config.GetUrl()) - MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() mngoCollections = collections mngoConfig = config if err := m.createClient(config.GetUrl()); err == nil { @@ -72,6 +70,8 @@ func (m *MongoDB) createClient(MongoURL string) error { UseJSONStructTags: true, NilSliceAsEmpty: true, } + MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() clientOptions := options.Client().ApplyURI(MongoURL).SetBSONOptions(bsonOpts) mngoClient, err = mongo.Connect(MngoCtx, clientOptions)