From 4dd161d0debde871f3a4d66fee440c4a55633124 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 27 Jul 2023 21:11:08 +0100 Subject: [PATCH] Configure DBClient to use JSON tags --- src/dbAccess/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dbAccess/client.go b/src/dbAccess/client.go index c7223e4..b9b5579 100644 --- a/src/dbAccess/client.go +++ b/src/dbAccess/client.go @@ -41,11 +41,16 @@ func getDbUri() string { // Provide the DB Connection to other functions var MongoClient (*mongo.Client) = initDataAccess() +// Configure bsonOpts +var bsonOpts = &options.BSONOptions{ + UseJSONStructTags: true, +} + // 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(dbUri)) + client, err := mongo.Connect(ctx, options.Client().ApplyURI(dbUri).SetBSONOptions(bsonOpts)) if err != nil { fmt.Println(err) log.Msg.Fatal("Error connecting to database: " + err.Error())