Configure DBClient to use JSON tags

This commit is contained in:
Fred Boniface 2023-07-27 21:11:08 +01:00
parent 0f9a99edfd
commit 4dd161d0de

View File

@ -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())