@@ -2615,7 +2615,7 @@ protected <S, T> List<T> doFind(String collectionName,
2615
2615
2616
2616
if (LOGGER .isDebugEnabled ()) {
2617
2617
2618
- Document mappedSort = getMappedSortObject (query , entityClass ) ;
2618
+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp . getSortObject (), entity ) : null ;
2619
2619
LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
2620
2620
serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), entityClass ,
2621
2621
collectionName ));
@@ -2640,9 +2640,10 @@ <S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPr
2640
2640
QueryContext queryContext = queryOperations .createQueryContext (new BasicQuery (query , fields ));
2641
2641
Document mappedFields = queryContext .getMappedFields (entity , projection );
2642
2642
Document mappedQuery = queryContext .getMappedQuery (entity );
2643
- Document mappedSort = getMappedSortObject (query , sourceClass );
2644
2643
2645
2644
if (LOGGER .isDebugEnabled ()) {
2645
+
2646
+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp .getSortObject (), sourceClass ) : null ;
2646
2647
LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
2647
2648
serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), sourceClass ,
2648
2649
collectionName ));
@@ -3006,12 +3007,17 @@ private Document getMappedSortObject(@Nullable Query query, Class<?> type) {
3006
3007
3007
3008
@ Nullable
3008
3009
private Document getMappedSortObject (Document sortObject , Class <?> type ) {
3010
+ return getMappedSortObject (sortObject , mappingContext .getPersistentEntity (type ));
3011
+ }
3012
+
3013
+ @ Nullable
3014
+ private Document getMappedSortObject (Document sortObject , MongoPersistentEntity <?> entity ) {
3009
3015
3010
3016
if (ObjectUtils .isEmpty (sortObject )) {
3011
3017
return null ;
3012
3018
}
3013
3019
3014
- return queryMapper .getMappedSort (sortObject , mappingContext . getPersistentEntity ( type ) );
3020
+ return queryMapper .getMappedSort (sortObject , entity );
3015
3021
}
3016
3022
3017
3023
/**
@@ -3364,7 +3370,7 @@ public T doWith(Document document) {
3364
3370
}
3365
3371
}
3366
3372
3367
- class QueryCursorPreparer implements CursorPreparer {
3373
+ class QueryCursorPreparer implements SortingQueryCursorPreparer {
3368
3374
3369
3375
private final Query query ;
3370
3376
@@ -3462,6 +3468,11 @@ public FindIterable<Document> prepare(FindIterable<Document> iterable) {
3462
3468
return cursorToUse ;
3463
3469
}
3464
3470
3471
+ @ Nullable
3472
+ @ Override
3473
+ public Document getSortObject () {
3474
+ return sortObject ;
3475
+ }
3465
3476
}
3466
3477
3467
3478
/**
0 commit comments