Skip to content

Commit 7555cc4

Browse files
committed
DATAMONGO-1425 - Polishing.
Add NotContaining to documentation. Add integration test for Containing/NotContaining on collection properties. Original pull request: #363.
1 parent 4fcec20 commit 7555cc4

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ public void setUp() throws InterruptedException {
8585
dave = new Person("Dave", "Matthews", 42);
8686
oliver = new Person("Oliver August", "Matthews", 4);
8787
carter = new Person("Carter", "Beauford", 49);
88+
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals"));
8889
Thread.sleep(10);
8990
boyd = new Person("Boyd", "Tinsley", 45);
91+
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
9092
stefan = new Person("Stefan", "Lessard", 34);
9193
leroi = new Person("Leroi", "Moore", 41);
9294

@@ -1268,4 +1270,26 @@ public void findsPersonsByFirstnameNotContains() throws Exception {
12681270
assertThat(result, not(hasItem(boyd)));
12691271
}
12701272

1273+
/**
1274+
* @see DATAMONGO-1425
1275+
*/
1276+
@Test
1277+
public void findBySkillsContains() throws Exception {
1278+
1279+
List<Person> result = repository.findBySkillsContains(Arrays.asList("Drums"));
1280+
assertThat(result.size(), is(1));
1281+
assertThat(result, hasItem(carter));
1282+
}
1283+
1284+
/**
1285+
* @see DATAMONGO-1425
1286+
*/
1287+
@Test
1288+
public void findBySkillsNotContains() throws Exception {
1289+
1290+
List<Person> result = repository.findBySkillsNotContains(Arrays.asList("Drums"));
1291+
assertThat(result.size(), is((int) (repository.count() - 1)));
1292+
assertThat(result, not(hasItem(carter)));
1293+
}
1294+
12711295
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
9393

9494
List<Person> findByFirstnameLikeOrderByLastnameAsc(String firstname, Sort sort);
9595

96+
List<Person> findBySkillsContains(List<String> skills);
97+
98+
List<Person> findBySkillsNotContains(List<String> skills);
99+
96100
@Query("{'age' : { '$lt' : ?0 } }")
97101
List<Person> findByAgeLessThan(int age, Sort sort);
98102

src/main/asciidoc/reference/mongo-repositories.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,18 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
212212
| `findByFirstnameContaining(String name)`
213213
| `{"firstname" : name} (name as regex)`
214214

215+
| `NotContaining` on String
216+
| `findByFirstnameNotContaining(String name)`
217+
| `{"firstname" : { "$not" : name}} (name as regex)`
218+
215219
| `Containing` on Collection
216220
| `findByAddressesContaining(Address address)`
217221
| `{"addresses" : { "$in" : address}}`
218222

223+
| `NotContaining` on Collection
224+
| `findByAddressesNotContaining(Address address)`
225+
| `{"addresses" : { "$not" : { "$in" : address}}}`
226+
219227
| `Regex`
220228
| `findByFirstnameRegex(String firstname)`
221229
| `{"firstname" : {"$regex" : firstname }}`

0 commit comments

Comments
 (0)