|
|
|
@ -3703,6 +3703,23 @@ public class MongoTemplateTests { |
|
|
|
assertThat(template.find(new BasicQuery("{}").with(Sort.by("id")), WithIdAndFieldAnnotation.class)).isNotEmpty(); |
|
|
|
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() { |
|
|
|
private AtomicReference<ImmutableVersioned> createAfterSaveReference() { |
|
|
|
|
|
|
|
|
|
|
|
AtomicReference<ImmutableVersioned> saved = new AtomicReference<>(); |
|
|
|
AtomicReference<ImmutableVersioned> saved = new AtomicReference<>(); |
|
|
|
|