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 ;
@@ -136,7 +137,7 @@ public Field slice(String field, int size) {
136137 */
137138 public Field slice (String field , int offset , int size ) {
138139
139- slices .put (field , new Integer [] { offset , size } );
140+ slices .put (field , Arrays . asList ( offset , size ) );
140141 return this ;
141142 }
142143
Original file line number Diff line number Diff line change @@ -3703,6 +3703,23 @@ public void sortOnIdFieldWithExplicitTypeShouldWork() {
37033703 assertThat (template .find (new BasicQuery ("{}" ).with (Sort .by ("id" )), WithIdAndFieldAnnotation .class )).isNotEmpty ();
37043704 }
37053705
3706+ @ Test // GH-3811
3707+ public void sliceShouldLimitCollectionValues () {
3708+
3709+ DocumentWithCollectionOfSimpleType source = new DocumentWithCollectionOfSimpleType ();
3710+ source .id = "id-1" ;
3711+ source .values = Arrays .asList ("spring" , "data" , "mongodb" );
3712+
3713+ template .save (source );
3714+
3715+ Criteria criteria = Criteria .where ("id" ).is (source .id );
3716+ Query query = Query .query (criteria );
3717+ query .fields ().slice ("values" , 0 , 1 );
3718+ DocumentWithCollectionOfSimpleType target = template .findOne (query , DocumentWithCollectionOfSimpleType .class );
3719+
3720+ assertThat (target .values ).containsExactly ("spring" );
3721+ }
3722+
37063723 private AtomicReference <ImmutableVersioned > createAfterSaveReference () {
37073724
37083725 AtomicReference <ImmutableVersioned > saved = new AtomicReference <>();
You can’t perform that action at this time.
0 commit comments