mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 19:22:46 +08:00
mongo single node
This commit is contained in:
parent
2bb6061a44
commit
2fc2801ad4
@ -17,15 +17,14 @@ import (
|
|||||||
//"go.mongodb.org/mongo-driver/bson"
|
//"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
// "go.mongodb.org/mongo-driver/mongo/options"
|
// "go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DB DataBases
|
var DB DataBases
|
||||||
|
|
||||||
type DataBases struct {
|
type DataBases struct {
|
||||||
MysqlDB mysqlDB
|
MysqlDB mysqlDB
|
||||||
mgoSession *mgo.Session
|
mgoSession *mgo.Session
|
||||||
redisPool *redis.Pool
|
redisPool *redis.Pool
|
||||||
mongoClient *mongo.Client
|
mongoClient *mongo.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +41,12 @@ func init() {
|
|||||||
// mongo init
|
// mongo init
|
||||||
// "mongodb://sysop:moon@localhost/records"
|
// "mongodb://sysop:moon@localhost/records"
|
||||||
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
||||||
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
|
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d&connect=direct",
|
||||||
config.Config.Mongo.DBAddress[0],config.Config.Mongo.DBDatabase,
|
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||||
config.Config.Mongo.DBMaxPoolSize)
|
config.Config.Mongo.DBMaxPoolSize)
|
||||||
|
|
||||||
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
if err != nil{
|
if err != nil {
|
||||||
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||||
time.Sleep(time.Duration(30) * time.Second)
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user