广汽安道拓Acura项目MES后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
587 B

package db
import (
"LAPP_ACURA_MOM_BACKEND/conf"
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"
)
var AppMongo *mongo.Client
func InitMongo() error {
//1.建立链接
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
dsn := fmt.Sprintf("mongodb://%s:%d", conf.DbConfig.Mongdbip, conf.DbConfig.Mongdbport)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(dsn))
if err != nil {
return err
}
if err = client.Ping(ctx, nil); err != nil {
return err
}
AppMongo = client
return err
}