Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-525

Customizable naming strategy for auto mapping domain object to database names


    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:


      As a developer, I would like to be able to set a naming strategy that can automatically convert my field and entity names inside my domain object to the format expected of the database. This will avoid unnecessary coupling of database details (i.e. the name of the table or column) to the domain object and avoid having to annotate every field in the domain object. This sort of functionality is similar to Hibernate's NamingStrategy interface (https://docs.jboss.org/hibernate/orm/4.0/javadocs/org/hibernate/cfg/NamingStrategy.html) except it would work for any type of database (in our case MongoDB).

      @Document(collection = "my_account")
      public class MyAccount {
      	private ObjectId id;
      	private String name;
      	private ObjectId customerId;

      In this example, the database document and fields expect the name to be lowercase with underscores but our domain object uses standard Java camelCase. If there was a naming strategy that automatically converted all camelCase fields or document names to underscores then we could avoid the @Field annotation and specifying the collection name. If any field needed a custom name that differed from the naming strategy, it could still be overridden with @Field.




            • Assignee:
              olivergierke Oliver Gierke
              ssheehy Steven Sheehy
              Last updater:
              Ankur Pathak
            • Votes:
              6 Vote for this issue
              9 Start watching this issue


              • Created: