Fix slice argument in query fields projection.
We now use a Collection instead of an Array to pass on $slice projection values for offset and limit. Closes: #3811 Original pull request: #3812.
This commit is contained in:
committed by
Mark Paluch
parent
6b394e4da6
commit
701153ac8f
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.query;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -136,7 +137,7 @@ public class Field {
|
||||
*/
|
||||
public Field slice(String field, int offset, int size) {
|
||||
|
||||
slices.put(field, new Integer[] { offset, size });
|
||||
slices.put(field, Arrays.asList(offset, size));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -3703,6 +3703,23 @@ public class MongoTemplateTests {
|
||||
assertThat(template.find(new BasicQuery("{}").with(Sort.by("id")), WithIdAndFieldAnnotation.class)).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test // GH-3811
|
||||
public void sliceShouldLimitCollectionValues() {
|
||||
|
||||
DocumentWithCollectionOfSimpleType source = new DocumentWithCollectionOfSimpleType();
|
||||
source.id = "id-1";
|
||||
source.values = Arrays.asList("spring", "data", "mongodb");
|
||||
|
||||
template.save(source);
|
||||
|
||||
Criteria criteria = Criteria.where("id").is(source.id);
|
||||
Query query = Query.query(criteria);
|
||||
query.fields().slice("values", 0, 1);
|
||||
DocumentWithCollectionOfSimpleType target = template.findOne(query, DocumentWithCollectionOfSimpleType.class);
|
||||
|
||||
assertThat(target.values).containsExactly("spring");
|
||||
}
|
||||
|
||||
private AtomicReference<ImmutableVersioned> createAfterSaveReference() {
|
||||
|
||||
AtomicReference<ImmutableVersioned> saved = new AtomicReference<>();
|
||||
|
||||
Reference in New Issue
Block a user