SpringData Mongo @Column equivalent annotation (@Property?)

10,722

Solution 1

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

Solution 2

You can use @Field

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

Share:
10,722
David Welch
Author by

David Welch

Software Engineer / Consultant

Updated on July 27, 2022

Comments

  • David Welch
    David Welch almost 2 years

    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

  • David Welch
    David Welch about 11 years
    Well, I feel a little dumb considering I've looked on multiple occasions. Thanks!
  • divinedragon
    divinedragon over 10 years
    Glad to reach here finally. Was looking for this for a really long time today.
  • jebeaudet
    jebeaudet over 9 years