I am new to Spring data and mongodb. I have a JSON object which represents a JSON Schema and I need to store that in mongodb using spring data. But the issue with JSON schem
You can map embedded documents using @DBref
@Document(collection = "first")
public class First {
@Id
private String id;
@DBRef
private Properties properties;
@Field
private List required;
// constructor
// getters and setter
}
public class Properties {
@Id
private String id;
@DBRef
private Name name;
@DBRef
private Age age;
// constructor
// getters and setter
}
public class Name { ... }
public class Age { ... }
http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb
http://docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/reference/html/mapping-chapter.html#mapping-usage-references
Or as Angelo Immediata suggested
@Document(collection = "first")
public class First {
@Id
private String id;
@Field
private Map properties;
@Field
private List required;
// constructor
// getters and setter
}
And you will need some custom read and write converters
http://docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/reference/html/mapping-chapter.html#mapping-explicit-converters