Skip to content

Commit e03520d

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 3829d58 commit e03520d

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
@@ -86,8 +86,10 @@ public void setUp() throws InterruptedException {
8686
dave = new Person("Dave", "Matthews", 42);
8787
oliver = new Person("Oliver August", "Matthews", 4);
8888
carter = new Person("Carter", "Beauford", 49);
89+
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals"));
8990
Thread.sleep(10);
9091
boyd = new Person("Boyd", "Tinsley", 45);
92+
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
9193
stefan = new Person("Stefan", "Lessard", 34);
9294
leroi = new Person("Leroi", "Moore", 41);
9395

@@ -1272,4 +1274,26 @@ public void findsPersonsByFirstnameNotContains() throws Exception {
12721274
assertThat(result, not(hasItem(boyd)));
12731275
}
12741276

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

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)