Is there a SpringData Mongo equivalent of the JPA @Column annotation?
Basically, I've got a POJO with a property that I want to store in Mongo with a different name. So, the following object:
public class Pojo{
@Property("bar")
private String foo = "Hello World";
}
would be persisted as:
{
"_class":"com.example.Pojo",
"bar" : "Hello World"
}
Note: I don't want to use the MappingMongoConverter
to explicitly do it
@Column annotation is used for Adding the column the name in the table of a particular MySQL database. Syntax: @Column(name=”DESC”, nullable=false, length=512) public String getDescription() {
@Document is an annotation provided by Spring data project. It is used to identify a domain object, which is persisted to MongoDB. So you can use it to map a Java class into a collection inside MongoDB. If you don't use Spring Data, you don't need this annotation.
The @Id annotation tells the mapper which property you want to use for the MongoDB _id property and the @Indexed annotation tells the mapping framework to call ensureIndex on that property of your document, making searches faster.
The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.
The Spring Data reference documentation lists @Field
as the annotation to customize the key and ordering of properties mapped to a MongoDB document.
You can use @Field
It lets you define custom key name in DB and the insert order
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