'Spring Boot Mongo Data - How to Set Naming Strategy
Dear Stack Overflow Community,
I am currently working on a Spring Boot project where the variable names are written in camel case. I also have a MongoDB database with fields written in snake case. Currently I am using @Field annotation provided by Spring Mongo Data to map each variable to its corresponding logical name like this:
@Field("var_name")
private String varName;
My question is - Is there a way to configure globally an automatic Camel Case to Snake Case conversion in Spring Mongo Data? If I have a model with many instance variables, it would be trivial to add a @Field annotation for each of them.
Thank you in advance.
Solution 1:[1]
Have you tried mappingContext.setFieldNamingStrategy(new SnakeCaseFieldNamingStrategy()) in your Mongo configuration class?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Qiuxuan Zhang |
