Spring Data MongoDB - Linking Example
This project contains examples for linking Documents using:
@DBRef@DocumentReference
DBRef
Use MongoDB native dbref for storing associations.
class Manager {
@DBRef
private List<Employee> employees;
// ...
}
DocumentReference
Link documents via their id.
class Manager {
@DocumentReference
private List<Employee> employees;
// ...
}
Link documents via a (non id) property.
class Manager {
@DocumentReference(lookup = "{ 'name' : ?#{#target} }")
private List<Employee> employees;
// ...
}
Link documents JPA style.
class Manager {
@ReadOnlyProperty
@DocumentReference(lookup="{'managerId':?#{#self._id} }")
private List<Employee> employees;
// ...
}
For more information please refer to the Reference Documentation.