From 93a5295085c95303b0cfbec09c1ce844859bfea7 Mon Sep 17 00:00:00 2001 From: Henry Kim Date: Thu, 4 Apr 2024 16:12:00 +0900 Subject: [PATCH] Add sort to query debug logging. Closes #4686 Original pull request: #4679 --- .../data/mongodb/core/MongoTemplate.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java index 8655dab2f2..9f1342eca8 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java @@ -2587,10 +2587,11 @@ protected List doFind(String collectionName, QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields)); Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass)); Document mappedQuery = queryContext.getMappedQuery(entity); + Document mappedSort = getMappedSortObject(query, entityClass); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("find using query: %s fields: %s for class: %s in collection: %s", - serializeToJsonSafely(mappedQuery), mappedFields, entityClass, collectionName)); + LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s", + serializeToJsonSafely(mappedQuery), mappedSort, mappedFields, entityClass, collectionName)); } return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null), @@ -2612,10 +2613,11 @@ List doFind(CollectionPreparer> collectionPr QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields)); Document mappedFields = queryContext.getMappedFields(entity, projection); Document mappedQuery = queryContext.getMappedQuery(entity); + Document mappedSort = getMappedSortObject(query, sourceClass); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("find using query: %s fields: %s for class: %s in collection: %s", - serializeToJsonSafely(mappedQuery), mappedFields, sourceClass, collectionName)); + LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s", + serializeToJsonSafely(mappedQuery), mappedSort, mappedFields, sourceClass, collectionName)); } return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null), preparer,