replace mongo driver

This commit is contained in:
wenxu12345 2022-02-21 15:20:39 +08:00
parent 9a35af9fb2
commit 7cf712daff

View File

@ -37,21 +37,21 @@ func init() {
// mongo init
// "mongodb://sysop:moon@localhost/records"
// uri := "mongodb://user:pass@sample.host:27017/?maxPoolSize=20&w=majority"
uri := fmt.Sprintf("mongodb://%s:%s@%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword,
config.Config.Mongo.DBAddress[0],config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil{
log.NewError(" mongo.Connect failed, try ", err.Error(), uri)
time.Sleep(time.Duration(30) * time.Second)
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err1 != nil {
log.NewError(" mongo.Connect failed, panic", err.Error(), uri)
panic(err1.Error())
}
}
//uri := fmt.Sprintf("mongodb://%s:%s@%s/%s/?maxPoolSize=%d",
// config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword,
// config.Config.Mongo.DBAddress[0],config.Config.Mongo.DBDatabase,
// config.Config.Mongo.DBMaxPoolSize)
//
//mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
//if err != nil{
// log.NewError(" mongo.Connect failed, try ", err.Error(), uri)
// time.Sleep(time.Duration(30) * time.Second)
// mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
// if err1 != nil {
// log.NewError(" mongo.Connect failed, panic", err.Error(), uri)
// panic(err1.Error())
// }
//}