Setting up logger data models

This commit is contained in:
2024-08-28 23:09:26 +02:00
parent 42bb32fdf1
commit 24537681ed
2 changed files with 85 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"log"
"time"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
@ -25,8 +26,13 @@ func main() {
if err != nil {
log.Panic(err)
}
// create a context in order to disconnect
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
// close connection
defer func() {
if err = mongoClient.Disconnect(context.TODO()); err != nil {
if err = mongoClient.Disconnect(ctx); err != nil {
panic(err)
}
}()