skip to Main Content

How to connect to mongodb running inside one container from golang app container – Docker

func GetDatabase() (database *mongo.Database, ctx context.Context, err error) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://mongodb:27017")) if err != nil { log.Println("database connection error", err) return nil, nil, err } err = client.Ping(context.TODO(), readpref.Primary()) if err…

VIEW QUESTION
Back To Top
Search