package dbAccess import ( "git.fjla.uk/owlboard/mq-client/helpers" "context" "time" "fmt" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" // "go.mongodb.org/mongo-driver/mongo/readpref" ) // Provide the DB Connection to other functions var MongoClient (*mongo.Client) = initDataAccess() // Initialise the DB Connection func initDataAccess() (*mongo.Client) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() client, err := mongo.Connect(ctx, options.Client().ApplyURI(helpers.DbUri)) if err != nil { fmt.Println(err) helpers.Log("Error connecting to database", 4) } else { helpers.Log("Connected to Database", 1) } return client }