@@ -2596,7 +2596,7 @@ protected <S, T> List<T> doFind(String collectionName,
2596
2596
2597
2597
if (LOGGER .isDebugEnabled ()) {
2598
2598
2599
- Document mappedSort = getMappedSortObject (query , entityClass ) ;
2599
+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp . getSortObject (), entity ) : null ;
2600
2600
LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
2601
2601
serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), entityClass ,
2602
2602
collectionName ));
@@ -2621,9 +2621,10 @@ <S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPr
2621
2621
QueryContext queryContext = queryOperations .createQueryContext (new BasicQuery (query , fields ));
2622
2622
Document mappedFields = queryContext .getMappedFields (entity , projection );
2623
2623
Document mappedQuery = queryContext .getMappedQuery (entity );
2624
- Document mappedSort = getMappedSortObject (query , sourceClass );
2625
2624
2626
2625
if (LOGGER .isDebugEnabled ()) {
2626
+
2627
+ Document mappedSort = preparer instanceof SortingQueryCursorPreparer sqcp ? getMappedSortObject (sqcp .getSortObject (), sourceClass ) : null ;
2627
2628
LOGGER .debug (String .format ("find using query: %s fields: %s sort: %s for class: %s in collection: %s" ,
2628
2629
serializeToJsonSafely (mappedQuery ), mappedFields , serializeToJsonSafely (mappedSort ), sourceClass ,
2629
2630
collectionName ));
@@ -2988,12 +2989,17 @@ private Document getMappedSortObject(@Nullable Query query, Class<?> type) {
2988
2989
2989
2990
@ Nullable
2990
2991
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 ) {
2991
2997
2992
2998
if (ObjectUtils .isEmpty (sortObject )) {
2993
2999
return null ;
2994
3000
}
2995
3001
2996
- return queryMapper .getMappedSort (sortObject , mappingContext . getPersistentEntity ( type ) );
3002
+ return queryMapper .getMappedSort (sortObject , entity );
2997
3003
}
2998
3004
2999
3005
/**
@@ -3346,7 +3352,7 @@ public T doWith(Document document) {
3346
3352
}
3347
3353
}
3348
3354
3349
- class QueryCursorPreparer implements CursorPreparer {
3355
+ class QueryCursorPreparer implements SortingQueryCursorPreparer {
3350
3356
3351
3357
private final Query query ;
3352
3358
@@ -3444,6 +3450,11 @@ public FindIterable<Document> prepare(FindIterable<Document> iterable) {
3444
3450
return cursorToUse ;
3445
3451
}
3446
3452
3453
+ @ Nullable
3454
+ @ Override
3455
+ public Document getSortObject () {
3456
+ return sortObject ;
3457
+ }
3447
3458
}
3448
3459
3449
3460
/**
0 commit comments