Reputation: 5733
I use this search method in my Spring data/MongoDB application:
@Query("{$text : { $search : ?0 } }")
List<DocumentFile> findBySearchString(final String searchString);
My question would be what I have to give in for searchString that I get DocumentFiles where two terms exists (e.g. term1 AND term2 or term1 + term2). Is there something like AND with Spring Data and MongoDB?
Upvotes: 0
Views: 52
Reputation: 219
Yes, you can achieve using mongo repository
List<DocumentFile> findByString1AndString2(String String1,String String2);
Ok, based on your last round of comments-can we do like this
Using mongo template
Criteria regex = Criteria.where("name").regex("*.xxxx.*", "i");
mongoOperations.find(new Query().addCriteria(regex), DocumentFile.class);
Using mongo repository
List<DocumentFile> documents= repository .findByQuery(".*ab.*");
interface repository extends MongoRepository<DocumentFile, String> {
@Query("{'name': {$regex: ?0 }})")
List<DocumentFile> findByQuery(String name);
}
Hope it will useful.
Upvotes: 1