From 9f3f08322ff1d1c3c4ee0feff615f29de92b6c3b Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Wed, 18 Oct 2023 16:18:14 +0800 Subject: [PATCH] fix: checkMongo uri --- tools/component/component.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/component/component.go b/tools/component/component.go index c995da5f1..05985bf37 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -171,9 +171,13 @@ func checkMongo() error { mongodbHosts += v + "," } } - client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI( - fmt.Sprintf("mongodb://%v:%v@%v/?authSource=admin", - config.Config.Mongo.Username, config.Config.Mongo.Password, mongodbHosts))) + var mongoURI string + if config.Config.Mongo.Uri == "" { + mongoURI = fmt.Sprintf("mongodb://%v:%v@%v/?authSource=admin", config.Config.Mongo.Username, config.Config.Mongo.Password, mongodbHosts) + } else { + mongoURI = config.Config.Mongo.Uri + } + client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(mongoURI)) if err != nil { return errs.Wrap(err) } else {