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.
 
 
mongoproov/main.go

34 lines
617 B

package main
import (
"context"
"fmt"
"os"
"time"
"go.mongodb.org/mongo-driver/mongo"
mongoOpt "go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
uri := os.Getenv("MONGO_URI")
opts := mongoOpt.Client().ApplyURI(uri)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
dbClient, err := mongo.Connect(ctx, opts)
if err != nil {
panic(fmt.Errorf("connect: %e", err))
}
for {
ctx, cancel = context.WithTimeout(context.Background(), time.Second*10)
fmt.Printf("ping returned: %e", dbClient.Ping(ctx, nil))
cancel()
time.Sleep(time.Second)
}
}