Skip to content

Commit b2cd7bb

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 0aff94b commit b2cd7bb

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
@@ -83,8 +83,10 @@ public void setUp() throws InterruptedException {
8383
dave = new Person("Dave", "Matthews", 42);
8484
oliver = new Person("Oliver August", "Matthews", 4);
8585
carter = new Person("Carter", "Beauford", 49);
86+
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals"));
8687
Thread.sleep(10);
8788
boyd = new Person("Boyd", "Tinsley", 45);
89+
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
8890
stefan = new Person("Stefan", "Lessard", 34);
8991
leroi = new Person("Leroi", "Moore", 41);
9092

@@ -1221,4 +1223,26 @@ public void findsPersonsByFirstnameNotContains() throws Exception {
12211223
assertThat(result, not(hasItem(boyd)));
12221224
}
12231225

1226+
/**
1227+
* @see DATAMONGO-1425
1228+
*/
1229+
@Test
1230+
public void findBySkillsContains() throws Exception {
1231+
1232+
List<Person> result = repository.findBySkillsContains(Arrays.asList("Drums"));
1233+
assertThat(result.size(), is(1));
1234+
assertThat(result, hasItem(carter));
1235+
}
1236+
1237+
/**
1238+
* @see DATAMONGO-1425
1239+
*/
1240+
@Test
1241+
public void findBySkillsNotContains() throws Exception {
1242+
1243+
List<Person> result = repository.findBySkillsNotContains(Arrays.asList("Drums"));
1244+
assertThat(result.size(), is((int) (repository.count() - 1)));
1245+
assertThat(result, not(hasItem(carter)));
1246+
}
1247+
12241248
}

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)