Is there any Spring Annotation to Set Default value for a Field (Mongo) ?
No need for spring annotations, this should do the trick:
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@Document
public class Doc {
@Field
private String field = "CustomDefaultValue";
}
You have to tell your Builder to use default value for some field using @Builder.Default(annotation).
Like this,
@Builder
@Document
public class Document {
@Builder.Default
private String field = "any_value";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With