SpringData Mongo @Column equivalent annotation (@Property?)

≯℡__Kan透↙ 提交于 2020-01-24 03:07:38

问题


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


回答1:


The Spring Data reference documentation lists @Field as the annotation to customize the key and ordering of properties mapped to a MongoDB document.




回答2:


You can use @Field

It lets you define custom key name in DB and the insert order



来源:https://stackoverflow.com/questions/15628575/springdata-mongo-column-equivalent-annotation-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!