diff --git a/pom.xml b/pom.xml
index 672f98f33a..5dd5ba50ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.10-SNAPSHOT
+ 4.2.10-4755-SNAPSHOT
pom
Spring Data MongoDB
diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml
index 223870f6ec..ade9a6ebd5 100644
--- a/spring-data-mongodb-benchmarks/pom.xml
+++ b/spring-data-mongodb-benchmarks/pom.xml
@@ -7,7 +7,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.10-SNAPSHOT
+ 4.2.10-4755-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml
index a223d945cc..27af69d711 100644
--- a/spring-data-mongodb-distribution/pom.xml
+++ b/spring-data-mongodb-distribution/pom.xml
@@ -15,7 +15,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.10-SNAPSHOT
+ 4.2.10-4755-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index 2088a56135..c2f09f89a0 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -13,7 +13,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.10-SNAPSHOT
+ 4.2.10-4755-SNAPSHOT
../pom.xml
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 551d2466f9..b76e36c408 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
@@ -99,6 +99,7 @@
import org.springframework.data.mongodb.core.query.Meta;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.core.query.SerializationUtils;
import org.springframework.data.mongodb.core.query.UpdateDefinition;
import org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter;
import org.springframework.data.mongodb.core.timeseries.Granularity;
@@ -179,6 +180,7 @@
* @author Bartłomiej Mazur
* @author Michael Krog
* @author Jakub Zurawa
+ * @author Marcin Grzejszczak
*/
public class MongoTemplate
implements MongoOperations, ApplicationContextAware, IndexOperationsProvider, ReadPreferenceAware {
@@ -491,6 +493,13 @@ protected Stream doStream(Query query, Class> entityType, String collec
Document mappedQuery = queryContext.getMappedQuery(persistentEntity);
Document mappedFields = queryContext.getMappedFields(persistentEntity, projection);
+ if (LOGGER.isDebugEnabled()) {
+ Document sort = getMappedSortObject(query, entityType);
+ LOGGER.debug(String.format(
+ "doStream using query: [%s] fields: [%s] sort: [%s] for class: [%s] in collection: [%s]",
+ serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(sort), entityType, collectionName));
+ }
+
CollectionPreparerDelegate readPreference = createDelegate(query);
FindIterable cursor = new QueryCursorPreparer(query, entityType).initiateFind(collection,
col -> readPreference.prepare(col).find(mappedQuery, Document.class).projection(mappedFields));
@@ -511,6 +520,11 @@ public Document executeCommand(String jsonCommand) {
Assert.hasText(jsonCommand, "JsonCommand must not be null nor empty");
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(String.format(
+ "Executing command: [%s]", jsonCommand));
+ }
+
return execute(db -> db.runCommand(Document.parse(jsonCommand), Document.class));
}
@@ -520,6 +534,11 @@ public Document executeCommand(Document command) {
Assert.notNull(command, "Command must not be null");
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(String.format(
+ "Executing command: [%s]", serializeToJsonSafely(command)));
+ }
+
return execute(db -> db.runCommand(command, Document.class));
}
@@ -529,6 +548,11 @@ public Document executeCommand(Document command, @Nullable ReadPreference readPr
Assert.notNull(command, "Command must not be null");
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(String.format(
+ "Executing command: [%s]%s", serializeToJsonSafely(command), readPreference != null ? (" with read preference: [" + readPreference + "]") : ""));
+ }
+
return execute(db -> readPreference != null //
? db.runCommand(command, readPreference, Document.class) //
: db.runCommand(command, Document.class));
@@ -562,7 +586,7 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
Document fieldsObject = query.getFieldsObject();
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(String.format("Executing query: %s fields: %s sort: %s in collection: %s",
+ LOGGER.debug(String.format("Executing query: [%s] fields: [%s] sort: [%s] in collection: [%s]",
serializeToJsonSafely(queryObject), fieldsObject, serializeToJsonSafely(sortObject), collectionName));
}
@@ -596,6 +620,11 @@ public T execute(String collectionName, CollectionCallback callback) {
Assert.notNull(collectionName, "CollectionName must not be null");
Assert.notNull(callback, "CollectionCallback must not be null");
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(String.format(
+ "Executing collection callback for collection: [%s]", collectionName));
+ }
+
try {
MongoCollection collection = getAndPrepareCollection(doGetDatabase(), collectionName);
return callback.doInCollection(collection);
@@ -956,7 +985,7 @@ public List findDistinct(Query query, String field, String collectionName
MongoIterable> result = execute(collectionName, (collection) -> {
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(String.format("Executing findDistinct using query %s for field: %s in collection: %s",
+ LOGGER.debug(String.format("Executing findDistinct using query [%s] for field: [%s] in collection: [%s]",
serializeToJsonSafely(mappedQuery), field, collectionName));
}
@@ -1188,7 +1217,7 @@ protected long doCount(CollectionPreparer collectionPreparer, String collectionN
if (LOGGER.isDebugEnabled()) {
LOGGER
- .debug(String.format("Executing count: %s in collection: %s", serializeToJsonSafely(filter), collectionName));
+ .debug(String.format("Executing count: [%s] in collection: [%s]", serializeToJsonSafely(filter), collectionName));
}
return countExecution.countDocuments(collectionPreparer, collectionName, filter, options);
@@ -1524,7 +1553,7 @@ protected T doSave(String collectionName, T objectToSave, MongoWriter wri
protected Object insertDocument(String collectionName, Document document, Class> entityClass) {
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(String.format("Inserting Document containing fields: %s in collection: %s", document.keySet(),
+ LOGGER.debug(String.format("Inserting Document containing fields: [%s] in collection: [%s]", document.keySet(),
collectionName));
}
@@ -1553,7 +1582,7 @@ protected List