@@ -2615,7 +2615,7 @@ protected <S, T> List<T> doFind(String collectionName,
26152615
26162616 if (LOGGER .isDebugEnabled ()) {
26172617
2618- Document mappedSort = getMappedSortObject (query , entityClass ) ;
2618+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp . getSortObject (), entity ) : null ;
26192619 LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
26202620 serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), entityClass ,
26212621 collectionName ));
@@ -2640,9 +2640,10 @@ <S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPr
26402640 QueryContext queryContext = queryOperations .createQueryContext (new BasicQuery (query , fields ));
26412641 Document mappedFields = queryContext .getMappedFields (entity , projection );
26422642 Document mappedQuery = queryContext .getMappedQuery (entity );
2643- Document mappedSort = getMappedSortObject (query , sourceClass );
26442643
26452644 if (LOGGER .isDebugEnabled ()) {
2645+
2646+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp .getSortObject (), sourceClass ) : null ;
26462647 LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
26472648 serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), sourceClass ,
26482649 collectionName ));
@@ -3006,12 +3007,17 @@ private Document getMappedSortObject(@Nullable Query query, Class<?> type) {
30063007
30073008 @ Nullable
30083009 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 ) {
30093015
30103016 if (ObjectUtils .isEmpty (sortObject )) {
30113017 return null ;
30123018 }
30133019
3014- return queryMapper .getMappedSort (sortObject , mappingContext . getPersistentEntity ( type ) );
3020+ return queryMapper .getMappedSort (sortObject , entity );
30153021 }
30163022
30173023 /**
@@ -3364,7 +3370,7 @@ public T doWith(Document document) {
33643370 }
33653371 }
33663372
3367- class QueryCursorPreparer implements CursorPreparer {
3373+ class QueryCursorPreparer implements SortingQueryCursorPreparer {
33683374
33693375 private final Query query ;
33703376
@@ -3462,6 +3468,11 @@ public FindIterable<Document> prepare(FindIterable<Document> iterable) {
34623468 return cursorToUse ;
34633469 }
34643470
3471+ @ Nullable
3472+ @ Override
3473+ public Document getSortObject () {
3474+ return sortObject ;
3475+ }
34653476 }
34663477
34673478 /**
0 commit comments