Question 1: No, @Document
is not strictly necessary at all. We just leverage this on application startup if you activate classpath-scanning for document classes. If you don't the persistence metadata scanning will be done on the first persistence operation. We traverse properties of domain objects then, so Address
will be discovered.
Question 2: You'll have to read the User
objects entirely as MongoDB currently does not allow returning sub-documents. So you'll have to query for the entire User
document but can restrict the fields being returned to the addresses
field using a fieldSpec
on the Query
object or the repository abstraction's @Query
annotation (see ref docs).