File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1515 */
1616package org .springframework .data .mongodb .core .query ;
1717
18+ import java .util .Arrays ;
1819import java .util .HashMap ;
1920import java .util .Map ;
2021import java .util .Map .Entry ;
@@ -192,7 +193,7 @@ public Field slice(String field, int size) {
192193 */
193194 public Field slice (String field , int offset , int size ) {
194195
195- slices .put (field , new Integer [] { offset , size } );
196+ slices .put (field , Arrays . asList ( offset , size ) );
196197 return this ;
197198 }
198199
Original file line number Diff line number Diff line change @@ -3768,6 +3768,23 @@ void shouldFindSubdocumentWithNullCorrectly() {
37683768 assertThat (loaded ).isNotNull ();
37693769 }
37703770
3771+ @ Test // GH-3811
3772+ public void sliceShouldLimitCollectionValues () {
3773+
3774+ DocumentWithCollectionOfSimpleType source = new DocumentWithCollectionOfSimpleType ();
3775+ source .id = "id-1" ;
3776+ source .values = Arrays .asList ("spring" , "data" , "mongodb" );
3777+
3778+ template .save (source );
3779+
3780+ Criteria criteria = Criteria .where ("id" ).is (source .id );
3781+ Query query = Query .query (criteria );
3782+ query .fields ().slice ("values" , 0 , 1 );
3783+ DocumentWithCollectionOfSimpleType target = template .findOne (query , DocumentWithCollectionOfSimpleType .class );
3784+
3785+ assertThat (target .values ).containsExactly ("spring" );
3786+ }
3787+
37713788 private AtomicReference <ImmutableVersioned > createAfterSaveReference () {
37723789
37733790 AtomicReference <ImmutableVersioned > saved = new AtomicReference <>();
You can’t perform that action at this time.
0 commit comments