This commit is contained in:
mr 2024-08-01 11:11:41 +02:00
parent 0256266107
commit b0f2cf46eb

View File

@ -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)