@@ -496,11 +496,10 @@ public <T> Flux<T> execute(ReactiveSessionCallback<T> action, Consumer<ClientSes
496496 session .startTransaction ();
497497 }
498498
499- return Flux
500- .usingWhen (Mono .just (session ), //
501- s -> ReactiveMongoTemplate .this .withSession (action , s ), //
502- ClientSession ::commitTransaction , //
503- ClientSession ::abortTransaction ) //
499+ return Flux .usingWhen (Mono .just (session ), //
500+ s -> ReactiveMongoTemplate .this .withSession (action , s ), //
501+ ClientSession ::commitTransaction , //
502+ ClientSession ::abortTransaction ) //
504503 .doFinally (signalType -> doFinally .accept (session ));
505504 });
506505 }
@@ -742,18 +741,22 @@ public Mono<Boolean> exists(Query query, String collectionName) {
742741 * (non-Javadoc)
743742 * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#exists(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
744743 */
745- public Mono <Boolean > exists (final Query query , @ Nullable Class <?> entityClass , String collectionName ) {
744+ public Mono <Boolean > exists (Query query , @ Nullable Class <?> entityClass , String collectionName ) {
746745
747746 if (query == null ) {
748747 throw new InvalidDataAccessApiUsageException ("Query passed in to exist can't be null" );
749748 }
750749
751750 return createFlux (collectionName , collection -> {
752751
753- Document mappedQuery = queryMapper .getMappedObject (query .getQueryObject (), getPersistentEntity (entityClass ));
754- FindPublisher <Document > findPublisher = collection .find (mappedQuery , Document .class )
752+ Document filter = queryMapper .getMappedObject (query .getQueryObject (), getPersistentEntity (entityClass ));
753+ FindPublisher <Document > findPublisher = collection .find (filter , Document .class )
755754 .projection (new Document ("_id" , 1 ));
756755
756+ if (LOGGER .isDebugEnabled ()) {
757+ LOGGER .debug ("exists: {} in collection: {}" , serializeToJsonSafely (filter ), collectionName );
758+ }
759+
757760 findPublisher = query .getCollation ().map (Collation ::toMongoCollation ).map (findPublisher ::collation )
758761 .orElse (findPublisher );
759762
@@ -835,6 +838,11 @@ public <T> Flux<T> findDistinct(Query query, String field, String collectionName
835838
836839 Flux <?> result = execute (collectionName , collection -> {
837840
841+ if (LOGGER .isDebugEnabled ()) {
842+ LOGGER .debug ("Executing findDistinct using query {} for field: {} in collection: {}" ,
843+ serializeToJsonSafely (mappedQuery ), field , collectionName );
844+ }
845+
838846 DistinctPublisher <T > publisher = collection .distinct (mappedFieldName , mappedQuery , mongoDriverCompatibleType );
839847
840848 return query .getCollation ().map (Collation ::toMongoCollation ).map (publisher ::collation ).orElse (publisher );
@@ -1151,7 +1159,7 @@ public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String coll
11511159
11521160 return createMono (collectionName , collection -> {
11531161
1154- final Document Document = query == null ? null
1162+ Document filter = query == null ? null
11551163 : queryMapper .getMappedObject (query .getQueryObject (),
11561164 entityClass == null ? null : mappingContext .getPersistentEntity (entityClass ));
11571165
@@ -1160,7 +1168,11 @@ public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String coll
11601168 query .getCollation ().map (Collation ::toMongoCollation ).ifPresent (options ::collation );
11611169 }
11621170
1163- return collection .count (Document , options );
1171+ if (LOGGER .isDebugEnabled ()) {
1172+ LOGGER .debug ("Executing count: {} in collection: {}" , serializeToJsonSafely (filter ), collectionName );
1173+ }
1174+
1175+ return collection .count (filter , options );
11641176 });
11651177 }
11661178
@@ -3165,7 +3177,7 @@ public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String coll
31653177
31663178 return createMono (collectionName , collection -> {
31673179
3168- final Document Document = query == null ? null
3180+ Document filter = query == null ? null
31693181 : delegate .queryMapper .getMappedObject (query .getQueryObject (),
31703182 entityClass == null ? null : delegate .mappingContext .getPersistentEntity (entityClass ));
31713183
@@ -3174,7 +3186,11 @@ public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String coll
31743186 query .getCollation ().map (Collation ::toMongoCollation ).ifPresent (options ::collation );
31753187 }
31763188
3177- return collection .countDocuments (Document , options );
3189+ if (LOGGER .isDebugEnabled ()) {
3190+ LOGGER .debug ("Executing count: {} in collection: {}" , serializeToJsonSafely (filter ), collectionName );
3191+ }
3192+
3193+ return collection .countDocuments (filter , options );
31783194 });
31793195 }
31803196 }
0 commit comments