13

I do have a simple MongoRepository and its entities do have a List<String> tags attribute. Is there a way to add a findBy method to the repository? Something like

List<...> findByInTags(@Param("tag") String tag);

So all entities containing the given string tag in there list tags will be returned.

I tried to solve it with a RestController and a custom findByTag endpoint. But I would like to use HATEOAS for the result format.

alexvetter
  • 1,998
  • 2
  • 16
  • 42

1 Answers1

23

From the spring-data-mongo unit tests: Person.java

@Document
public class Person extends Contact {
    private String firstname;
    private String lastname;
    ...
    private Set<Address> shippingAddresses;

And the PersonRepository

    /**
* Returns the {@link Person} with the given {@link Address} as shipping address.
*
* @param address
* @return
*/
Person findByShippingAddresses(Address address);

IIRC, this kind of syntax also works with Collections. So you should be able to use

List<...> findByTag(String tag);

Martin Baumgartner
  • 3,524
  • 3
  • 20
  • 31