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 @@ -3768,6 +3768,23 @@ void shouldFindSubdocumentWithNullCorrectly() {
3768
3768
assertThat (loaded ).isNotNull ();
3769
3769
}
3770
3770
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
+
3771
3788
private AtomicReference <ImmutableVersioned > createAfterSaveReference () {
3772
3789
3773
3790
AtomicReference <ImmutableVersioned > saved = new AtomicReference <>();
You can’t perform that action at this time.
0 commit comments