How to map mongodb collections on spring-data-mongodb when the names differ from your pojo definition


package com.wordpress.vrsbrazil;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

/*When collection name is different*/
@Document(collection="myCollectionName")
public class MyPojo {

@Id
public String id;

/*When field name is different*/
@Field("collectionFieldName")
public Integer myAttribute;

//getters and setters

}

Advertisements