Configure DBClient to use JSON tags
This commit is contained in:
		
							parent
							
								
									0f9a99edfd
								
							
						
					
					
						commit
						4dd161d0de
					
				| @ -41,11 +41,16 @@ func getDbUri() string { | |||||||
| // Provide the DB Connection to other functions | // Provide the DB Connection to other functions | ||||||
| var MongoClient (*mongo.Client) = initDataAccess() | var MongoClient (*mongo.Client) = initDataAccess() | ||||||
| 
 | 
 | ||||||
|  | // Configure bsonOpts | ||||||
|  | var bsonOpts = &options.BSONOptions{ | ||||||
|  | 	UseJSONStructTags: true, | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Initialise the DB Connection | // Initialise the DB Connection | ||||||
| func initDataAccess() *mongo.Client { | func initDataAccess() *mongo.Client { | ||||||
| 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||||||
| 	defer cancel() | 	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 { | 	if err != nil { | ||||||
| 		fmt.Println(err) | 		fmt.Println(err) | ||||||
| 		log.Msg.Fatal("Error connecting to database: " + err.Error()) | 		log.Msg.Fatal("Error connecting to database: " + err.Error()) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user