@@ -45,20 +45,24 @@ func (m *mongo) Initialization() error {
4545 opts = internal .Mongo .GetClientOptions ()
4646 }
4747 ctx := context .Background ()
48- client , err := qmgo . Open ( ctx , & qmgo.Config {
48+ config := & qmgo.Config {
4949 Uri : global .GVA_CONFIG .Mongo .Uri (),
5050 Coll : global .GVA_CONFIG .Mongo .Coll ,
5151 Database : global .GVA_CONFIG .Mongo .Database ,
5252 MinPoolSize : & global .GVA_CONFIG .Mongo .MinPoolSize ,
5353 MaxPoolSize : & global .GVA_CONFIG .Mongo .MaxPoolSize ,
5454 SocketTimeoutMS : & global .GVA_CONFIG .Mongo .SocketTimeoutMs ,
5555 ConnectTimeoutMS : & global .GVA_CONFIG .Mongo .ConnectTimeoutMs ,
56- Auth : & qmgo.Credential {
56+ }
57+ if global .GVA_CONFIG .Mongo .Username != "" && global .GVA_CONFIG .Mongo .Password != "" {
58+ config .Auth = & qmgo.Credential {
5759 Username : global .GVA_CONFIG .Mongo .Username ,
5860 Password : global .GVA_CONFIG .Mongo .Password ,
5961 AuthSource : global .GVA_CONFIG .Mongo .AuthSource ,
60- },
61- }, opts ... )
62+ }
63+ }
64+ client , err := qmgo .Open (ctx , config , opts ... )
65+
6266 if err != nil {
6367 return errors .Wrap (err , "链接mongodb数据库失败!" )
6468 }
0 commit comments