@@ -2596,7 +2596,7 @@ protected <S, T> List<T> doFind(String collectionName,
25962596
25972597 if (LOGGER .isDebugEnabled ()) {
25982598
2599- Document mappedSort = getMappedSortObject (query , entityClass ) ;
2599+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp . getSortObject (), entity ) : null ;
26002600 LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
26012601 serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), entityClass ,
26022602 collectionName ));
@@ -2621,9 +2621,10 @@ <S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPr
26212621 QueryContext queryContext = queryOperations .createQueryContext (new BasicQuery (query , fields ));
26222622 Document mappedFields = queryContext .getMappedFields (entity , projection );
26232623 Document mappedQuery = queryContext .getMappedQuery (entity );
2624- Document mappedSort = getMappedSortObject (query , sourceClass );
26252624
26262625 if (LOGGER .isDebugEnabled ()) {
2626+
2627+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp .getSortObject (), sourceClass ) : null ;
26272628 LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
26282629 serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), sourceClass ,
26292630 collectionName ));
@@ -2988,12 +2989,17 @@ private Document getMappedSortObject(@Nullable Query query, Class<?> type) {
29882989
29892990 @ Nullable
29902991 private Document getMappedSortObject (Document sortObject , Class <?> type ) {
2992+ return getMappedSortObject (sortObject , mappingContext .getPersistentEntity (type ));
2993+ }
2994+
2995+ @ Nullable
2996+ private Document getMappedSortObject (Document sortObject , MongoPersistentEntity <?> entity ) {
29912997
29922998 if (ObjectUtils .isEmpty (sortObject )) {
29932999 return null ;
29943000 }
29953001
2996- return queryMapper .getMappedSort (sortObject , mappingContext . getPersistentEntity ( type ) );
3002+ return queryMapper .getMappedSort (sortObject , entity );
29973003 }
29983004
29993005 /**
@@ -3346,7 +3352,7 @@ public T doWith(Document document) {
33463352 }
33473353 }
33483354
3349- class QueryCursorPreparer implements CursorPreparer {
3355+ class QueryCursorPreparer implements SortingQueryCursorPreparer {
33503356
33513357 private final Query query ;
33523358
@@ -3444,6 +3450,11 @@ public FindIterable<Document> prepare(FindIterable<Document> iterable) {
34443450 return cursorToUse ;
34453451 }
34463452
3453+ @ Nullable
3454+ @ Override
3455+ public Document getSortObject () {
3456+ return sortObject ;
3457+ }
34473458 }
34483459
34493460 /**
0 commit comments