timetable-mgr/src/mongo.go

34 lines
722 B
Go
Raw Normal View History

2023-07-15 22:32:46 +01:00
package main
import (
"context"
"time"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
// "go.mongodb.org/mongo-driver/mongo/readpref"
)
type Service struct {
id string
}
var client (*mongo.Client) = initDataAccess()
func initDataAccess() (*mongo.Client) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
client, err := mongo.Connect(ctx, options.Client().ApplyURI(dbUri))
if err != nil {
fmt.Println(err)
Log("Error connecting to database", 4)
} else {
Log("Connected to Database", 1)
}
return client
}
func PutMany(collection string, data []Service) bool {
return false
}