File tree 2 files changed +19
-1
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package org .springframework .data .mongodb .core .query ;
17
17
18
+ import java .util .Arrays ;
18
19
import java .util .HashMap ;
19
20
import java .util .Map ;
20
21
import java .util .Map .Entry ;
@@ -192,7 +193,7 @@ public Field slice(String field, int size) {
192
193
*/
193
194
public Field slice (String field , int offset , int size ) {
194
195
195
- slices .put (field , new Integer [] { offset , size } );
196
+ slices .put (field , Arrays . asList ( offset , size ) );
196
197
return this ;
197
198
}
198
199
Original file line number Diff line number Diff line change @@ -3703,6 +3703,23 @@ public void sortOnIdFieldWithExplicitTypeShouldWork() {
3703
3703
assertThat (template .find (new BasicQuery ("{}" ).with (Sort .by ("id" )), WithIdAndFieldAnnotation .class )).isNotEmpty ();
3704
3704
}
3705
3705
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
+
3706
3723
private AtomicReference <ImmutableVersioned > createAfterSaveReference () {
3707
3724
3708
3725
AtomicReference <ImmutableVersioned > saved = new AtomicReference <>();
You can’t perform that action at this time.
0 commit comments