|
|
@ -1,6 +1,7 @@
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/config"
|
|
|
|
mongo2 "Open_IM/test/mongo"
|
|
|
|
mongo2 "Open_IM/test/mongo"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
@ -10,9 +11,22 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
clientOptions := options.Client().ApplyURI("mongodb://127.0.0.1:37017/openIM/?maxPoolSize=100")
|
|
|
|
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
|
|
|
|
|
|
|
if config.Config.Mongo.DBUri != "" {
|
|
|
|
|
|
|
|
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
|
|
|
|
|
|
|
|
uri = config.Config.Mongo.DBUri
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" {
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
|
|
|
|
|
|
|
|
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
|
|
|
|
|
|
|
config.Config.Mongo.DBMaxPoolSize)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
mongo2.Client, err = mongo.Connect(context.TODO(), clientOptions)
|
|
|
|
mongo2.Client, err = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|