Skip to content

Commit 85826e1

Browse files
mp911dechristophstrobl
authored andcommitted
Document limitations around nullable properties.
See: #4308 Original Pull Request: #4317
1 parent 14a722f commit 85826e1

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ExecutableFindOperation.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import java.util.stream.Stream;
2121

2222
import org.springframework.dao.DataAccessException;
23-
import org.springframework.data.domain.Window;
23+
import org.springframework.data.domain.KeysetScrollPosition;
2424
import org.springframework.data.domain.ScrollPosition;
25+
import org.springframework.data.domain.Window;
2526
import org.springframework.data.geo.GeoResults;
2627
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
2728
import org.springframework.data.mongodb.core.query.NearQuery;
@@ -128,10 +129,13 @@ default Optional<T> first() {
128129
/**
129130
* Return a window of elements either starting or resuming at
130131
* {@link org.springframework.data.domain.ScrollPosition}.
132+
* <p>
133+
* When using {@link KeysetScrollPosition}, make sure to use non-nullable
134+
* {@link org.springframework.data.domain.Sort sort properties} as MongoDB does not support criteria to reconstruct
135+
* a query result from absent document fields or {@code null} values through {@code $gt/$lt} operators.
131136
*
132137
* @param scrollPosition the scroll position.
133138
* @return a window of the resulting elements.
134-
* @throws IllegalStateException if a potential {@literal KeysetScrollPosition} contains an invalid position.
135139
* @since 4.1
136140
* @see org.springframework.data.domain.OffsetScrollPosition
137141
* @see org.springframework.data.domain.KeysetScrollPosition

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -807,19 +807,24 @@ <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, Strin
807807
<T> List<T> find(Query query, Class<T> entityClass, String collectionName);
808808

809809
/**
810-
* Query for a window window of objects of type T from the specified collection. <br />
810+
* Query for a window of objects of type T from the specified collection. <br />
811811
* Make sure to either set {@link Query#skip(long)} or {@link Query#with(KeysetScrollPosition)} along with
812812
* {@link Query#limit(int)} to limit large query results for efficient scrolling. <br />
813813
* Result objects are converted from the MongoDB native representation using an instance of {@see MongoConverter}.
814814
* Unless configured otherwise, an instance of {@link MappingMongoConverter} will be used. <br />
815815
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
816816
* to map objects since the test for class type is done in the client and not on the server.
817+
* <p>
818+
* When using {@link KeysetScrollPosition}, make sure to use non-nullable {@link org.springframework.data.domain.Sort
819+
* sort properties} as MongoDB does not support criteria to reconstruct a query result from absent document fields or
820+
* {@code null} values through {@code $gt/$lt} operators.
817821
*
818822
* @param query the query class that specifies the criteria used to find a record and also an optional fields
819823
* specification. Must not be {@literal null}.
820824
* @param entityType the parametrized type of the returned window.
821825
* @return the converted window.
822-
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid position.
826+
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid
827+
* position.
823828
* @since 4.1
824829
* @see Query#with(org.springframework.data.domain.OffsetScrollPosition)
825830
* @see Query#with(org.springframework.data.domain.KeysetScrollPosition)
@@ -834,13 +839,18 @@ <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, Strin
834839
* Unless configured otherwise, an instance of {@link MappingMongoConverter} will be used. <br />
835840
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
836841
* to map objects since the test for class type is done in the client and not on the server.
842+
* <p>
843+
* When using {@link KeysetScrollPosition}, make sure to use non-nullable {@link org.springframework.data.domain.Sort
844+
* sort properties} as MongoDB does not support criteria to reconstruct a query result from absent document fields or
845+
* {@code null} values through {@code $gt/$lt} operators.
837846
*
838847
* @param query the query class that specifies the criteria used to find a record and also an optional fields
839848
* specification. Must not be {@literal null}.
840849
* @param entityType the parametrized type of the returned window.
841850
* @param collectionName name of the collection to retrieve the objects from.
842851
* @return the converted window.
843-
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid position.
852+
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid
853+
* position.
844854
* @since 4.1
845855
* @see Query#with(org.springframework.data.domain.OffsetScrollPosition)
846856
* @see Query#with(org.springframework.data.domain.KeysetScrollPosition)

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperation.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
import reactor.core.publisher.Flux;
1919
import reactor.core.publisher.Mono;
2020

21-
import org.springframework.data.domain.Window;
21+
import org.springframework.data.domain.KeysetScrollPosition;
2222
import org.springframework.data.domain.ScrollPosition;
23+
import org.springframework.data.domain.Window;
2324
import org.springframework.data.geo.GeoResult;
2425
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
2526
import org.springframework.data.mongodb.core.query.NearQuery;
@@ -91,6 +92,10 @@ interface TerminatingFind<T> {
9192

9293
/**
9394
* Return a scroll of elements either starting or resuming at {@link ScrollPosition}.
95+
* <p>
96+
* When using {@link KeysetScrollPosition}, make sure to use non-nullable
97+
* {@link org.springframework.data.domain.Sort sort properties} as MongoDB does not support criteria to reconstruct
98+
* a query result from absent document fields or {@code null} values through {@code $gt/$lt} operators.
9499
*
95100
* @param scrollPosition the scroll position.
96101
* @return a scroll of the resulting elements.

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,17 @@ Mono<MongoCollection<Document>> createView(String name, String source, Aggregati
473473
* Unless configured otherwise, an instance of {@link MappingMongoConverter} will be used. <br />
474474
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
475475
* to map objects since the test for class type is done in the client and not on the server.
476+
* <p>
477+
* When using {@link KeysetScrollPosition}, make sure to use non-nullable {@link org.springframework.data.domain.Sort
478+
* sort properties} as MongoDB does not support criteria to reconstruct a query result from absent document fields or
479+
* {@code null} values through {@code $gt/$lt} operators.
476480
*
477481
* @param query the query class that specifies the criteria used to find a record and also an optional fields
478482
* specification. Must not be {@literal null}.
479483
* @param entityType the parametrized type of the returned list.
480484
* @return {@link Mono} emitting the converted window.
481-
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid position.
485+
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid
486+
* position.
482487
* @since 4.1
483488
* @see Query#with(org.springframework.data.domain.OffsetScrollPosition)
484489
* @see Query#with(org.springframework.data.domain.KeysetScrollPosition)
@@ -493,13 +498,18 @@ Mono<MongoCollection<Document>> createView(String name, String source, Aggregati
493498
* Unless configured otherwise, an instance of {@link MappingMongoConverter} will be used. <br />
494499
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
495500
* to map objects since the test for class type is done in the client and not on the server.
501+
* <p>
502+
* When using {@link KeysetScrollPosition}, make sure to use non-nullable {@link org.springframework.data.domain.Sort
503+
* sort properties} as MongoDB does not support criteria to reconstruct a query result from absent document fields or
504+
* {@code null} values through {@code $gt/$lt} operators.
496505
*
497506
* @param query the query class that specifies the criteria used to find a record and also an optional fields
498507
* specification. Must not be {@literal null}.
499508
* @param entityType the parametrized type of the returned list.
500509
* @param collectionName name of the collection to retrieve the objects from.
501510
* @return {@link Mono} emitting the converted window.
502-
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid position.
511+
* @throws IllegalStateException if a potential {@link Query#getKeyset() KeysetScrollPosition} contains an invalid
512+
* position.
503513
* @since 4.1
504514
* @see Query#with(org.springframework.data.domain.OffsetScrollPosition)
505515
* @see Query#with(org.springframework.data.domain.KeysetScrollPosition)

0 commit comments

Comments
 (0)