doFind(@Nullable CursorPreparer preparer) {
Document queryObject = query.getQueryObject();
Document fieldsObject = query.getFieldsObject();
- return template.doFind(getCollectionName(), queryObject, fieldsObject, domainType, returnType,
+ return template.doFind(template.createDelegate(query), getCollectionName(), queryObject, fieldsObject, domainType,
+ returnType,
getCursorPreparer(query, preparer));
}
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 3738a48df0..2afbcd0fe2 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
@@ -55,6 +55,7 @@
import org.springframework.data.mongodb.MongoDatabaseUtils;
import org.springframework.data.mongodb.SessionSynchronization;
import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
+import org.springframework.data.mongodb.core.CollectionPreparerSupport.CollectionPreparerDelegate;
import org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext;
import org.springframework.data.mongodb.core.EntityOperations.AdaptibleEntity;
import org.springframework.data.mongodb.core.QueryOperations.AggregationDefinition;
@@ -66,6 +67,7 @@
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;
import org.springframework.data.mongodb.core.aggregation.AggregationOptions;
+import org.springframework.data.mongodb.core.aggregation.AggregationOptions.Builder;
import org.springframework.data.mongodb.core.aggregation.AggregationPipeline;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
@@ -83,7 +85,6 @@
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Collation;
import org.springframework.data.mongodb.core.query.Meta;
-import org.springframework.data.mongodb.core.query.Meta.CursorOption;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.UpdateDefinition;
@@ -112,7 +113,23 @@
import com.mongodb.client.result.UpdateResult;
/**
- * Primary implementation of {@link MongoOperations}.
+ * Primary implementation of {@link MongoOperations}. It simplifies the use of imperative MongoDB usage and helps to
+ * avoid common errors. It executes core MongoDB workflow, leaving application code to provide {@link Document} and
+ * extract results. This class executes BSON queries or updates, initiating iteration over {@link FindIterable} and
+ * catching MongoDB exceptions and translating them to the generic, more informative exception hierarchy defined in the
+ * org.springframework.dao package. Can be used within a service implementation via direct instantiation with a
+ * {@link MongoDatabaseFactory} reference, or get prepared in an application context and given to services as bean
+ * reference.
+ *
+ * Note: The {@link MongoDatabaseFactory} should always be configured as a bean in the application context, in the first
+ * case given to the service directly, in the second case to the prepared template.
+ *
{@link ReadPreference} and {@link com.mongodb.ReadConcern}
+ *
+ * {@code ReadPreference} and {@code ReadConcern} are generally considered from {@link Query} and
+ * {@link AggregationOptions} objects for the action to be executed on a particular {@link MongoCollection}.
+ *
+ * You can also set the default {@link #setReadPreference(ReadPreference) ReadPreference} on the template level to
+ * generally apply a {@link ReadPreference}.
*
* @author Thomas Risberg
* @author Graeme Rocher
@@ -141,7 +158,8 @@
* @author Bartłomiej Mazur
* @author Michael Krog
*/
-public class MongoTemplate implements MongoOperations, ApplicationContextAware, IndexOperationsProvider {
+public class MongoTemplate
+ implements MongoOperations, ApplicationContextAware, IndexOperationsProvider, ReadPreferenceAware {
private static final Log LOGGER = LogFactory.getLog(MongoTemplate.class);
private static final WriteResultChecking DEFAULT_WRITE_RESULT_CHECKING = WriteResultChecking.NONE;
@@ -293,6 +311,16 @@ public void setReadPreference(@Nullable ReadPreference readPreference) {
this.readPreference = readPreference;
}
+ @Override
+ public boolean hasReadPreference() {
+ return this.readPreference != null;
+ }
+
+ @Override
+ public ReadPreference getReadPreference() {
+ return this.readPreference;
+ }
+
/**
* Configure whether lifecycle events such as {@link AfterLoadEvent}, {@link BeforeSaveEvent}, etc. should be
* published or whether emission should be suppressed. Enabled by default.
@@ -363,10 +391,10 @@ private void useEstimatedCount(boolean enabled, BiPredicate {
+ this.countExecution = (collectionPreparer, collectionName, filter, options) -> {
if (!estimationFilter.test(filter, options)) {
- return doExactCount(collectionName, filter, options);
+ return doExactCount(collectionPreparer, collectionName, filter, options);
}
EstimatedDocumentCountOptions estimatedDocumentCountOptions = new EstimatedDocumentCountOptions();
@@ -374,7 +402,7 @@ private void useEstimatedCount(boolean enabled, BiPredicate Stream doStream(Query query, Class> entityType, String collec
Document mappedQuery = queryContext.getMappedQuery(persistentEntity);
Document mappedFields = queryContext.getMappedFields(persistentEntity, projection);
+ CollectionPreparerDelegate readPreference = createDelegate(query);
FindIterable cursor = new QueryCursorPreparer(query, entityType).initiateFind(collection,
- col -> col.find(mappedQuery, Document.class).projection(mappedFields));
+ col -> readPreference.prepare(col).find(mappedQuery, Document.class).projection(mappedFields));
return new CloseableIterableCursorAdapter<>(cursor, exceptionTranslator,
new ProjectingReadCallback<>(mongoConverter, projection, collectionName)).stream();
@@ -517,7 +546,7 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
serializeToJsonSafely(queryObject), sortObject, fieldsObject, collectionName));
}
- this.executeQueryInternal(new FindCallback(queryObject, fieldsObject, null),
+ this.executeQueryInternal(new FindCallback(createDelegate(query), queryObject, fieldsObject, null),
preparer != null ? preparer : CursorPreparer.NO_OP_PREPARER, documentCallbackHandler, collectionName);
}
@@ -765,7 +794,7 @@ public T findOne(Query query, Class entityClass, String collectionName) {
if (ObjectUtils.isEmpty(query.getSortObject())) {
- return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(),
+ return doFindOne(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(),
new QueryCursorPreparer(query, entityClass), entityClass);
} else {
query.limit(1);
@@ -797,7 +826,7 @@ public boolean exists(Query query, @Nullable Class> entityClass, String collec
Document mappedQuery = queryContext.getMappedQuery(entityClass, this::getPersistentEntity);
return execute(collectionName,
- new ExistsCallback(mappedQuery, queryContext.getCollation(entityClass).orElse(null)));
+ new ExistsCallback(createDelegate(query), mappedQuery, queryContext.getCollation(entityClass).orElse(null)));
}
// Find methods that take a Query to express the query and that return a List of objects.
@@ -814,7 +843,7 @@ public List find(Query query, Class entityClass, String collectionName
Assert.notNull(collectionName, "CollectionName must not be null");
Assert.notNull(entityClass, "EntityClass must not be null");
- return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
+ return doFind(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(), entityClass,
new QueryCursorPreparer(query, entityClass));
}
@@ -834,7 +863,8 @@ public T findById(Object id, Class entityClass, String collectionName) {
String idKey = operations.getIdPropertyName(entityClass);
- return doFindOne(collectionName, new Document(idKey, id), new Document(), entityClass);
+ return doFindOne(collectionName, CollectionPreparer.identity(), new Document(idKey, id), new Document(),
+ entityClass);
}
@Override
@@ -867,10 +897,7 @@ public List findDistinct(Query query, String field, String collectionName
serializeToJsonSafely(mappedQuery), field, collectionName));
}
- QueryCursorPreparer preparer = new QueryCursorPreparer(query, entityClass);
- if (preparer.hasReadPreference()) {
- collection = collection.withReadPreference(preparer.getReadPreference());
- }
+ collection = createDelegate(query).prepare(collection);
DistinctIterable iterable = collection.distinct(mappedFieldName, mappedQuery, mongoDriverCompatibleType);
distinctQueryContext.applyCollation(entityClass, iterable::collation);
@@ -920,8 +947,15 @@ public GeoResults geoNear(NearQuery near, Class> domainType, String col
String collection = StringUtils.hasText(collectionName) ? collectionName : getCollectionName(domainType);
String distanceField = operations.nearQueryDistanceFieldName(domainType);
+ Builder optionsBuilder = AggregationOptions.builder().collation(near.getCollation());
+ Query query = near.getQuery();
+
+ if (query != null && query.hasReadPreference()) {
+ optionsBuilder.readPreference(query.getReadPreference());
+ }
+
Aggregation $geoNear = TypedAggregation.newAggregation(domainType, Aggregation.geoNear(near, distanceField))
- .withOptions(AggregationOptions.builder().collation(near.getCollation()).build());
+ .withOptions(optionsBuilder.build());
AggregationResults results = aggregate($geoNear, collection, Document.class);
EntityProjection projection = operations.introspectProjection(returnType, domainType);
@@ -986,7 +1020,7 @@ public T findAndModify(Query query, UpdateDefinition update, FindAndModifyOp
operations.forType(entityClass).getCollation(query).ifPresent(optionsToUse::collation);
}
- return doFindAndModify(collectionName, query.getQueryObject(), query.getFieldsObject(),
+ return doFindAndModify(createDelegate(query), collectionName, query.getQueryObject(), query.getFieldsObject(),
getMappedSortObject(query, entityClass), entityClass, update, optionsToUse);
}
@@ -1008,6 +1042,7 @@ public T findAndReplace(Query query, S replacement, FindAndReplaceOptions
QueryContext queryContext = queryOperations.createQueryContext(query);
EntityProjection projection = operations.introspectProjection(resultType, entityType);
+ CollectionPreparerDelegate collectionPreparer = createDelegate(query);
Document mappedQuery = queryContext.getMappedQuery(entity);
Document mappedFields = queryContext.getMappedFields(entity, projection);
Document mappedSort = queryContext.getMappedSort(entity);
@@ -1018,7 +1053,7 @@ public T findAndReplace(Query query, S replacement, FindAndReplaceOptions
maybeEmitEvent(new BeforeSaveEvent<>(replacement, mappedReplacement, collectionName));
maybeCallBeforeSave(replacement, mappedReplacement, collectionName);
- T saved = doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
+ T saved = doFindAndReplace(collectionPreparer, collectionName, mappedQuery, mappedFields, mappedSort,
queryContext.getCollation(entityType).orElse(null), entityType, mappedReplacement, options, projection);
if (saved != null) {
@@ -1046,7 +1081,7 @@ public T findAndRemove(Query query, Class entityClass, String collectionN
Assert.notNull(entityClass, "EntityClass must not be null");
Assert.notNull(collectionName, "CollectionName must not be null");
- return doFindAndRemove(collectionName, query.getQueryObject(), query.getFieldsObject(),
+ return doFindAndRemove(createDelegate(query), collectionName, query.getQueryObject(), query.getFieldsObject(),
getMappedSortObject(query, entityClass), operations.forType(entityClass).getCollation(query).orElse(null),
entityClass);
}
@@ -1078,17 +1113,19 @@ public long count(Query query, @Nullable Class> entityClass, String collection
CountOptions options = countContext.getCountOptions(entityClass);
Document mappedQuery = countContext.getMappedQuery(entityClass, mappingContext::getPersistentEntity);
- return doCount(collectionName, mappedQuery, options);
+ CollectionPreparerDelegate readPreference = createDelegate(query);
+ return doCount(readPreference, collectionName, mappedQuery, options);
}
- protected long doCount(String collectionName, Document filter, CountOptions options) {
+ protected long doCount(CollectionPreparer collectionPreparer, String collectionName, Document filter,
+ CountOptions options) {
if (LOGGER.isDebugEnabled()) {
LOGGER
.debug(String.format("Executing count: %s in collection: %s", serializeToJsonSafely(filter), collectionName));
}
- return countExecution.countDocuments(collectionName, filter, options);
+ return countExecution.countDocuments(collectionPreparer, collectionName, filter, options);
}
/*
@@ -1097,11 +1134,13 @@ protected long doCount(String collectionName, Document filter, CountOptions opti
*/
@Override
public long estimatedCount(String collectionName) {
- return doEstimatedCount(collectionName, new EstimatedDocumentCountOptions());
+ return doEstimatedCount(CollectionPreparerDelegate.of(this), collectionName, new EstimatedDocumentCountOptions());
}
- protected long doEstimatedCount(String collectionName, EstimatedDocumentCountOptions options) {
- return execute(collectionName, collection -> collection.estimatedDocumentCount(options));
+ protected long doEstimatedCount(CollectionPreparer> collectionPreparer,
+ String collectionName, EstimatedDocumentCountOptions options) {
+ return execute(collectionName,
+ collection -> collectionPreparer.prepare(collection).estimatedDocumentCount(options));
}
@Override
@@ -1112,12 +1151,13 @@ public long exactCount(Query query, @Nullable Class> entityClass, String colle
CountOptions options = countContext.getCountOptions(entityClass);
Document mappedQuery = countContext.getMappedQuery(entityClass, mappingContext::getPersistentEntity);
- return doExactCount(collectionName, mappedQuery, options);
+ return doExactCount(createDelegate(query), collectionName, mappedQuery, options);
}
- protected long doExactCount(String collectionName, Document filter, CountOptions options) {
- return execute(collectionName,
- collection -> collection.countDocuments(CountQuery.of(filter).toQueryDocument(), options));
+ protected long doExactCount(CollectionPreparer> collectionPreparer, String collectionName,
+ Document filter, CountOptions options) {
+ return execute(collectionName, collection -> collectionPreparer.prepare(collection)
+ .countDocuments(CountQuery.of(filter).toQueryDocument(), options));
}
protected boolean countCanBeEstimated(Document filter, CountOptions options) {
@@ -1177,8 +1217,8 @@ protected void ensureNotCollectionLike(@Nullable Object source) {
*/
protected MongoCollection prepareCollection(MongoCollection collection) {
- if (this.readPreference != null) {
- collection = collection.withReadPreference(readPreference);
+ if (this.readPreference != null && this.readPreference != collection.getReadPreference()) {
+ return collection.withReadPreference(readPreference);
}
return collection;
@@ -1754,7 +1794,7 @@ public List findAll(Class entityClass) {
@Override
public List findAll(Class entityClass, String collectionName) {
return executeFindMultiInternal(
- new FindCallback(new Document(), new Document(),
+ new FindCallback(CollectionPreparer.identity(), new Document(), new Document(),
operations.forType(entityClass).getCollation().map(Collation::toMongoCollation).orElse(null)),
CursorPreparer.NO_OP_PREPARER, new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName),
collectionName);
@@ -1812,7 +1852,9 @@ public List mapReduce(Query query, Class> domainType, String inputColle
String mapFunc = replaceWithResourceIfNecessary(mapFunction);
String reduceFunc = replaceWithResourceIfNecessary(reduceFunction);
- MongoCollection inputCollection = getAndPrepareCollection(doGetDatabase(), inputCollectionName);
+ CollectionPreparerDelegate readPreference = createDelegate(query);
+ MongoCollection inputCollection = readPreference
+ .prepare(getAndPrepareCollection(doGetDatabase(), inputCollectionName));
// MapReduceOp
MapReduceIterable mapReduce = inputCollection.mapReduce(mapFunc, reduceFunc, Document.class);
@@ -1977,6 +2019,9 @@ protected List doFindAndDelete(String collectionName, Query query, Class<
if (!CollectionUtils.isEmpty(result)) {
Query byIdInQuery = operations.getByIdInQuery(result);
+ if (query.hasReadPreference()) {
+ byIdInQuery.withReadPreference(query.getReadPreference());
+ }
remove(byIdInQuery, entityClass, collectionName);
}
@@ -2032,7 +2077,7 @@ protected AggregationResults doAggregate(Aggregation aggregation, String
return execute(collectionName, collection -> {
List rawResult = new ArrayList<>();
-
+ CollectionPreparerDelegate delegate = CollectionPreparerDelegate.of(options);
Class> domainType = aggregation instanceof TypedAggregation ? ((TypedAggregation>) aggregation).getInputType()
: null;
@@ -2040,7 +2085,7 @@ protected AggregationResults doAggregate(Aggregation aggregation, String
() -> operations.forType(domainType) //
.getCollation());
- AggregateIterable aggregateIterable = collection.aggregate(pipeline, Document.class) //
+ AggregateIterable aggregateIterable = delegate.prepare(collection).aggregate(pipeline, Document.class) //
.collation(collation.map(Collation::toMongoCollation).orElse(null)) //
.allowDiskUse(options.isAllowDiskUse());
@@ -2103,7 +2148,9 @@ protected Stream aggregateStream(Aggregation aggregation, String collecti
return execute(collectionName, (CollectionCallback>) collection -> {
- AggregateIterable cursor = collection.aggregate(pipeline, Document.class) //
+ CollectionPreparerDelegate delegate = CollectionPreparerDelegate.of(options);
+
+ AggregateIterable cursor = delegate.prepare(collection).aggregate(pipeline, Document.class) //
.allowDiskUse(options.isAllowDiskUse());
if (options.getCursorBatchSize() != null) {
@@ -2344,14 +2391,16 @@ private CreateCollectionOptions getCreateCollectionOptions(Document document) {
* The query document is specified as a standard {@link Document} and so is the fields specification.
*
* @param collectionName name of the collection to retrieve the objects from.
+ * @param collectionPreparer the preparer to prepare the collection for the actual use.
* @param query the query document that specifies the criteria used to find a record.
* @param fields the document that specifies the fields to be returned.
* @param entityClass the parameterized type of the returned list.
* @return the converted object or {@literal null} if none exists.
*/
@Nullable
- protected T doFindOne(String collectionName, Document query, Document fields, Class entityClass) {
- return doFindOne(collectionName, query, fields, CursorPreparer.NO_OP_PREPARER, entityClass);
+ protected T doFindOne(String collectionName, CollectionPreparer> collectionPreparer,
+ Document query, Document fields, Class entityClass) {
+ return doFindOne(collectionName, collectionPreparer, query, fields, CursorPreparer.NO_OP_PREPARER, entityClass);
}
/**
@@ -2359,17 +2408,18 @@ protected T doFindOne(String collectionName, Document query, Document fields
* The query document is specified as a standard {@link Document} and so is the fields specification.
*
* @param collectionName name of the collection to retrieve the objects from.
+ * @param collectionPreparer the preparer to prepare the collection for the actual use.
* @param query the query document that specifies the criteria used to find a record.
* @param fields the document that specifies the fields to be returned.
- * @param entityClass the parameterized type of the returned list.
* @param preparer the preparer used to modify the cursor on execution.
+ * @param entityClass the parameterized type of the returned list.
* @return the converted object or {@literal null} if none exists.
* @since 2.2
*/
@Nullable
@SuppressWarnings("ConstantConditions")
- protected T doFindOne(String collectionName, Document query, Document fields, CursorPreparer preparer,
- Class entityClass) {
+ protected T doFindOne(String collectionName, CollectionPreparer> collectionPreparer,
+ Document query, Document fields, CursorPreparer preparer, Class entityClass) {
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
@@ -2382,7 +2432,7 @@ protected T doFindOne(String collectionName, Document query, Document fields
serializeToJsonSafely(query), mappedFields, entityClass, collectionName));
}
- return executeFindOneInternal(new FindOneCallback(mappedQuery, mappedFields, preparer),
+ return executeFindOneInternal(new FindOneCallback(collectionPreparer, mappedQuery, mappedFields, preparer),
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
}
@@ -2391,13 +2441,15 @@ protected T doFindOne(String collectionName, Document query, Document fields
* query document is specified as a standard Document and so is the fields specification.
*
* @param collectionName name of the collection to retrieve the objects from
+ * @param collectionPreparer the preparer to prepare the collection for the actual use.
* @param query the query document that specifies the criteria used to find a record
* @param fields the document that specifies the fields to be returned
* @param entityClass the parameterized type of the returned list.
* @return the List of converted objects.
*/
- protected List doFind(String collectionName, Document query, Document fields, Class entityClass) {
- return doFind(collectionName, query, fields, entityClass, null,
+ protected List doFind(String collectionName, CollectionPreparer> collectionPreparer,
+ Document query, Document fields, Class entityClass) {
+ return doFind(collectionName, collectionPreparer, query, fields, entityClass, null,
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName));
}
@@ -2407,6 +2459,7 @@ protected List doFind(String collectionName, Document query, Document fie
* specified as a standard Document and so is the fields specification.
*
* @param collectionName name of the collection to retrieve the objects from.
+ * @param collectionPreparer the preparer to prepare the collection for the actual use.
* @param query the query document that specifies the criteria used to find a record.
* @param fields the document that specifies the fields to be returned.
* @param entityClass the parameterized type of the returned list.
@@ -2414,14 +2467,15 @@ protected List doFind(String collectionName, Document query, Document fie
* (apply limits, skips and so on).
* @return the {@link List} of converted objects.
*/
- protected List doFind(String collectionName, Document query, Document fields, Class entityClass,
- CursorPreparer preparer) {
- return doFind(collectionName, query, fields, entityClass, preparer,
+ protected List doFind(String collectionName, CollectionPreparer> collectionPreparer,
+ Document query, Document fields, Class entityClass, CursorPreparer preparer) {
+ return doFind(collectionName, collectionPreparer, query, fields, entityClass, preparer,
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName));
}
- protected List doFind(String collectionName, Document query, Document fields, Class entityClass,
- @Nullable CursorPreparer preparer, DocumentCallback objectCallback) {
+ protected List doFind(String collectionName,
+ CollectionPreparer> collectionPreparer, Document query, Document fields,
+ Class entityClass, @Nullable CursorPreparer preparer, DocumentCallback objectCallback) {
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
@@ -2434,7 +2488,7 @@ protected List doFind(String collectionName, Document query, Document
serializeToJsonSafely(mappedQuery), mappedFields, entityClass, collectionName));
}
- return executeFindMultiInternal(new FindCallback(mappedQuery, mappedFields, null),
+ return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null),
preparer != null ? preparer : CursorPreparer.NO_OP_PREPARER, objectCallback, collectionName);
}
@@ -2444,8 +2498,8 @@ protected List doFind(String collectionName, Document query, Document
*
* @since 2.0
*/
- List doFind(String collectionName, Document query, Document fields, Class sourceClass,
- Class targetClass, CursorPreparer preparer) {
+ List doFind(CollectionPreparer> collectionPreparer, String collectionName,
+ Document query, Document fields, Class sourceClass, Class targetClass, CursorPreparer preparer) {
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(sourceClass);
EntityProjection projection = operations.introspectProjection(targetClass, sourceClass);
@@ -2459,7 +2513,7 @@ List doFind(String collectionName, Document query, Document fields, Cl
serializeToJsonSafely(mappedQuery), mappedFields, sourceClass, collectionName));
}
- return executeFindMultiInternal(new FindCallback(mappedQuery, mappedFields, null), preparer,
+ return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null), preparer,
new ProjectingReadCallback<>(mongoConverter, projection, collectionName), collectionName);
}
@@ -2533,8 +2587,8 @@ Document getMappedValidator(Validator validator, Class> domainType) {
* @return the List of converted objects.
*/
@SuppressWarnings("ConstantConditions")
- protected T doFindAndRemove(String collectionName, Document query, Document fields, Document sort,
- @Nullable Collation collation, Class entityClass) {
+ protected T doFindAndRemove(CollectionPreparer collectionPreparer, String collectionName, Document query,
+ Document fields, Document sort, @Nullable Collation collation, Class entityClass) {
EntityReader super T, Bson> readerToUse = this.mongoConverter;
@@ -2545,14 +2599,15 @@ protected T doFindAndRemove(String collectionName, Document query, Document
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
- return executeFindOneInternal(
- new FindAndRemoveCallback(queryMapper.getMappedObject(query, entity), fields, sort, collation),
+ return executeFindOneInternal(new FindAndRemoveCallback(collectionPreparer,
+ queryMapper.getMappedObject(query, entity), fields, sort, collation),
new ReadDocumentCallback<>(readerToUse, entityClass, collectionName), collectionName);
}
@SuppressWarnings("ConstantConditions")
- protected T doFindAndModify(String collectionName, Document query, Document fields, Document sort,
- Class entityClass, UpdateDefinition update, @Nullable FindAndModifyOptions options) {
+ protected T doFindAndModify(CollectionPreparer collectionPreparer, String collectionName, Document query,
+ Document fields, Document sort, Class entityClass, UpdateDefinition update,
+ @Nullable FindAndModifyOptions options) {
EntityReader super T, Bson> readerToUse = this.mongoConverter;
@@ -2577,7 +2632,7 @@ protected T doFindAndModify(String collectionName, Document query, Document
}
return executeFindOneInternal(
- new FindAndModifyCallback(mappedQuery, fields, sort, mappedUpdate,
+ new FindAndModifyCallback(collectionPreparer, mappedQuery, fields, sort, mappedUpdate,
update.getArrayFilters().stream().map(ArrayFilter::asDocument).collect(Collectors.toList()), options),
new ReadDocumentCallback<>(readerToUse, entityClass, collectionName), collectionName);
}
@@ -2598,14 +2653,18 @@ protected T doFindAndModify(String collectionName, Document query, Document
* {@literal false} and {@link FindAndReplaceOptions#isUpsert() upsert} is {@literal false}.
*/
@Nullable
- protected T doFindAndReplace(String collectionName, Document mappedQuery, Document mappedFields,
- Document mappedSort, @Nullable com.mongodb.client.model.Collation collation, Class> entityType,
- Document replacement, FindAndReplaceOptions options, Class resultType) {
+ protected T doFindAndReplace(CollectionPreparer collectionPreparer, String collectionName, Document mappedQuery,
+ Document mappedFields, Document mappedSort, @Nullable com.mongodb.client.model.Collation collation,
+ Class> entityType, Document replacement, FindAndReplaceOptions options, Class resultType) {
EntityProjection projection = operations.introspectProjection(resultType, entityType);
- return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort, collation, entityType, replacement,
- options, projection);
+ return doFindAndReplace(collectionPreparer, collectionName, mappedQuery, mappedFields, mappedSort, collation,
+ entityType, replacement, options, projection);
+ }
+
+ CollectionPreparerDelegate createDelegate(Query query) {
+ return CollectionPreparerDelegate.of(query);
}
/**
@@ -2625,9 +2684,9 @@ protected T doFindAndReplace(String collectionName, Document mappedQuery, Do
* @since 3.4
*/
@Nullable
- private T doFindAndReplace(String collectionName, Document mappedQuery, Document mappedFields,
- Document mappedSort, @Nullable com.mongodb.client.model.Collation collation, Class> entityType,
- Document replacement, FindAndReplaceOptions options, EntityProjection projection) {
+ private T doFindAndReplace(CollectionPreparer collectionPreparer, String collectionName, Document mappedQuery,
+ Document mappedFields, Document mappedSort, @Nullable com.mongodb.client.model.Collation collation,
+ Class> entityType, Document replacement, FindAndReplaceOptions options, EntityProjection projection) {
if (LOGGER.isDebugEnabled()) {
LOGGER
@@ -2638,9 +2697,9 @@ private T doFindAndReplace(String collectionName, Document mappedQuery, Docu
serializeToJsonSafely(mappedSort), entityType, serializeToJsonSafely(replacement), collectionName));
}
- return executeFindOneInternal(
- new FindAndReplaceCallback(mappedQuery, mappedFields, mappedSort, replacement, collation, options),
- new ProjectingReadCallback<>(mongoConverter, projection, collectionName), collectionName);
+ return executeFindOneInternal(new FindAndReplaceCallback(collectionPreparer, mappedQuery, mappedFields, mappedSort,
+ replacement, collation, options), new ProjectingReadCallback<>(mongoConverter, projection, collectionName),
+ collectionName);
}
/**
@@ -2810,12 +2869,15 @@ static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex,
*/
private static class FindOneCallback implements CollectionCallback {
+ private final CollectionPreparer> collectionPreparer;
private final Document query;
private final Optional fields;
private final CursorPreparer cursorPreparer;
- FindOneCallback(Document query, Document fields, CursorPreparer preparer) {
+ FindOneCallback(CollectionPreparer> collectionPreparer, Document query, Document fields,
+ CursorPreparer preparer) {
+ this.collectionPreparer = collectionPreparer;
this.query = query;
this.fields = Optional.of(fields).filter(it -> !ObjectUtils.isEmpty(fields));
this.cursorPreparer = preparer;
@@ -2824,7 +2886,8 @@ private static class FindOneCallback implements CollectionCallback {
@Override
public Document doInCollection(MongoCollection collection) throws MongoException, DataAccessException {
- FindIterable iterable = cursorPreparer.initiateFind(collection, col -> col.find(query, Document.class));
+ FindIterable iterable = cursorPreparer.initiateFind(collection,
+ col -> collectionPreparer.prepare(col).find(query, Document.class));
if (LOGGER.isDebugEnabled()) {
@@ -2851,15 +2914,18 @@ public Document doInCollection(MongoCollection collection) throws Mong
*/
private static class FindCallback implements CollectionCallback> {
+ private final CollectionPreparer> collectionPreparer;
private final Document query;
private final Document fields;
private final @Nullable com.mongodb.client.model.Collation collation;
- public FindCallback(Document query, Document fields, @Nullable com.mongodb.client.model.Collation collation) {
+ public FindCallback(CollectionPreparer> collectionPreparer, Document query,
+ Document fields, @Nullable com.mongodb.client.model.Collation collation) {
Assert.notNull(query, "Query must not be null");
Assert.notNull(fields, "Fields must not be null");
+ this.collectionPreparer = collectionPreparer;
this.query = query;
this.fields = fields;
this.collation = collation;
@@ -2869,7 +2935,8 @@ public FindCallback(Document query, Document fields, @Nullable com.mongodb.clien
public FindIterable doInCollection(MongoCollection collection)
throws MongoException, DataAccessException {
- FindIterable findIterable = collection.find(query, Document.class).projection(fields);
+ FindIterable findIterable = collectionPreparer.prepare(collection).find(query, Document.class)
+ .projection(fields);
if (collation != null) {
findIterable = findIterable.collation(collation);
@@ -2887,11 +2954,14 @@ public FindIterable doInCollection(MongoCollection collectio
*/
private class ExistsCallback implements CollectionCallback {
+ private final CollectionPreparer collectionPreparer;
private final Document mappedQuery;
private final com.mongodb.client.model.Collation collation;
- ExistsCallback(Document mappedQuery, com.mongodb.client.model.Collation collation) {
+ ExistsCallback(CollectionPreparer collectionPreparer, Document mappedQuery,
+ com.mongodb.client.model.Collation collation) {
+ this.collectionPreparer = collectionPreparer;
this.mappedQuery = mappedQuery;
this.collation = collation;
}
@@ -2899,7 +2969,7 @@ private class ExistsCallback implements CollectionCallback {
@Override
public Boolean doInCollection(MongoCollection collection) throws MongoException, DataAccessException {
- return doCount(collection.getNamespace().getCollectionName(), mappedQuery,
+ return doCount(collectionPreparer, collection.getNamespace().getCollectionName(), mappedQuery,
new CountOptions().limit(1).collation(collation)) > 0;
}
}
@@ -2912,12 +2982,15 @@ public Boolean doInCollection(MongoCollection collection) throws Mongo
*/
private static class FindAndRemoveCallback implements CollectionCallback {
+ private final CollectionPreparer> collectionPreparer;
private final Document query;
private final Document fields;
private final Document sort;
private final Optional collation;
- FindAndRemoveCallback(Document query, Document fields, Document sort, @Nullable Collation collation) {
+ FindAndRemoveCallback(CollectionPreparer> collectionPreparer, Document query,
+ Document fields, Document sort, @Nullable Collation collation) {
+ this.collectionPreparer = collectionPreparer;
this.query = query;
this.fields = fields;
@@ -2931,12 +3004,13 @@ public Document doInCollection(MongoCollection collection) throws Mong
FindOneAndDeleteOptions opts = new FindOneAndDeleteOptions().sort(sort).projection(fields);
collation.map(Collation::toMongoCollation).ifPresent(opts::collation);
- return collection.findOneAndDelete(query, opts);
+ return collectionPreparer.prepare(collection).findOneAndDelete(query, opts);
}
}
private static class FindAndModifyCallback implements CollectionCallback {
+ private final CollectionPreparer> collectionPreparer;
private final Document query;
private final Document fields;
private final Document sort;
@@ -2944,9 +3018,10 @@ private static class FindAndModifyCallback implements CollectionCallback arrayFilters;
private final FindAndModifyOptions options;
- FindAndModifyCallback(Document query, Document fields, Document sort, Object update, List arrayFilters,
- FindAndModifyOptions options) {
+ FindAndModifyCallback(CollectionPreparer> collectionPreparer, Document query,
+ Document fields, Document sort, Object update, List arrayFilters, FindAndModifyOptions options) {
+ this.collectionPreparer = collectionPreparer;
this.query = query;
this.fields = fields;
this.sort = sort;
@@ -2975,9 +3050,9 @@ public Document doInCollection(MongoCollection collection) throws Mong
}
if (update instanceof Document) {
- return collection.findOneAndUpdate(query, (Document) update, opts);
+ return collectionPreparer.prepare(collection).findOneAndUpdate(query, (Document) update, opts);
} else if (update instanceof List) {
- return collection.findOneAndUpdate(query, (List) update, opts);
+ return collectionPreparer.prepare(collection).findOneAndUpdate(query, (List) update, opts);
}
throw new IllegalArgumentException(String.format("Using %s is not supported in findOneAndUpdate", update));
@@ -2993,6 +3068,7 @@ public Document doInCollection(MongoCollection collection) throws Mong
*/
private static class FindAndReplaceCallback implements CollectionCallback {
+ private final CollectionPreparer> collectionPreparer;
private final Document query;
private final Document fields;
private final Document sort;
@@ -3000,9 +3076,10 @@ private static class FindAndReplaceCallback implements CollectionCallback> collectionPreparer, Document query,
+ Document fields, Document sort, Document update, @Nullable com.mongodb.client.model.Collation collation,
+ FindAndReplaceOptions options) {
+ this.collectionPreparer = collectionPreparer;
this.query = query;
this.fields = fields;
this.sort = sort;
@@ -3027,7 +3104,7 @@ public Document doInCollection(MongoCollection collection) throws Mong
opts.returnDocument(ReturnDocument.AFTER);
}
- return collection.findOneAndReplace(query, update, opts);
+ return collectionPreparer.prepare(collection).findOneAndReplace(query, update, opts);
}
}
@@ -3209,11 +3286,6 @@ public FindIterable prepare(FindIterable iterable) {
return cursorToUse;
}
- @Override
- public ReadPreference getReadPreference() {
- return query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS) ? ReadPreference.primaryPreferred()
- : null;
- }
}
/**
@@ -3399,6 +3471,7 @@ protected boolean countCanBeEstimated(Document filter, CountOptions options) {
@FunctionalInterface
interface CountExecution {
- long countDocuments(String collection, Document filter, CountOptions options);
+ long countDocuments(CollectionPreparer collectionPreparer, String collection, Document filter,
+ CountOptions options);
}
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java
index 46d27b68bb..4dcf62aacd 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java
@@ -20,6 +20,7 @@
import org.bson.Document;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.data.mongodb.core.CollectionPreparerSupport.ReactiveCollectionPreparerDelegate;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.SerializationUtils;
@@ -67,8 +68,8 @@ static class ReactiveFindSupport
private final String collection;
private final Query query;
- ReactiveFindSupport(ReactiveMongoTemplate template, Class> domainType, Class returnType,
- String collection, Query query) {
+ ReactiveFindSupport(ReactiveMongoTemplate template, Class> domainType, Class returnType, String collection,
+ Query query) {
this.template = template;
this.domainType = domainType;
@@ -169,8 +170,8 @@ private Flux doFind(@Nullable FindPublisherPreparer preparer) {
Document queryObject = query.getQueryObject();
Document fieldsObject = query.getFieldsObject();
- return template.doFind(getCollectionName(), queryObject, fieldsObject, domainType, returnType,
- preparer != null ? preparer : getCursorPreparer(query));
+ return template.doFind(getCollectionName(), ReactiveCollectionPreparerDelegate.of(query), queryObject,
+ fieldsObject, domainType, returnType, preparer != null ? preparer : getCursorPreparer(query));
}
@SuppressWarnings("unchecked")
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
index 5e33adb753..1eb27c652e 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
@@ -70,6 +70,7 @@
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
import org.springframework.data.mongodb.ReactiveMongoDatabaseUtils;
import org.springframework.data.mongodb.SessionSynchronization;
+import org.springframework.data.mongodb.core.CollectionPreparerSupport.ReactiveCollectionPreparerDelegate;
import org.springframework.data.mongodb.core.EntityOperations.AdaptibleEntity;
import org.springframework.data.mongodb.core.QueryOperations.AggregationDefinition;
import org.springframework.data.mongodb.core.QueryOperations.CountContext;
@@ -105,7 +106,6 @@
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Collation;
import org.springframework.data.mongodb.core.query.Meta;
-import org.springframework.data.mongodb.core.query.Meta.CursorOption;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.UpdateDefinition;
@@ -147,9 +147,18 @@
* extract results. This class executes BSON queries or updates, initiating iteration over {@link FindPublisher} and
* catching MongoDB exceptions and translating them to the generic, more informative exception hierarchy defined in the
* org.springframework.dao package. Can be used within a service implementation via direct instantiation with a
- * {@link SimpleReactiveMongoDatabaseFactory} reference, or get prepared in an application context and given to services
- * as bean reference. Note: The {@link SimpleReactiveMongoDatabaseFactory} should always be configured as a bean in the
- * application context, in the first case given to the service directly, in the second case to the prepared template.
+ * {@link ReactiveMongoDatabaseFactory} reference, or get prepared in an application context and given to services as
+ * bean reference.
+ *
+ * Note: The {@link ReactiveMongoDatabaseFactory} should always be configured as a bean in the application context, in
+ * the first case given to the service directly, in the second case to the prepared template.
+ *
{@link ReadPreference} and {@link com.mongodb.ReadConcern}
+ *
+ * {@code ReadPreference} and {@code ReadConcern} are generally considered from {@link Query} and
+ * {@link AggregationOptions} objects for the action to be executed on a particular {@link MongoCollection}.
+ *
+ * You can also set the default {@link #setReadPreference(ReadPreference) ReadPreference} on the template level to
+ * generally apply a {@link ReadPreference}.
*
* @author Mark Paluch
* @author Christoph Strobl
@@ -756,8 +765,8 @@ public Mono findOne(Query query, Class entityClass) {
public Mono findOne(Query query, Class entityClass, String collectionName) {
if (ObjectUtils.isEmpty(query.getSortObject())) {
- return doFindOne(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
- new QueryFindPublisherPreparer(query, entityClass));
+ return doFindOne(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
+ query.getFieldsObject(), entityClass, new QueryFindPublisherPreparer(query, entityClass));
}
query.limit(1);
@@ -783,10 +792,11 @@ public Mono exists(Query query, @Nullable Class> entityClass, String
return createFlux(collectionName, collection -> {
+ ReactiveCollectionPreparerDelegate collectionPreparer = ReactiveCollectionPreparerDelegate.of(query);
QueryContext queryContext = queryOperations.createQueryContext(query);
Document filter = queryContext.getMappedQuery(entityClass, this::getPersistentEntity);
- FindPublisher findPublisher = collection.find(filter, Document.class)
+ FindPublisher findPublisher = collectionPreparer.prepare(collection).find(filter, Document.class)
.projection(new Document("_id", 1));
if (LOGGER.isDebugEnabled()) {
@@ -811,8 +821,8 @@ public Flux find(@Nullable Query query, Class entityClass, String coll
return findAll(entityClass, collectionName);
}
- return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
- new QueryFindPublisherPreparer(query, entityClass));
+ return doFind(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
+ query.getFieldsObject(), entityClass, new QueryFindPublisherPreparer(query, entityClass));
}
@Override
@@ -825,7 +835,8 @@ public Mono findById(Object id, Class entityClass, String collectionNa
String idKey = operations.getIdPropertyName(entityClass);
- return doFindOne(collectionName, new Document(idKey, id), null, entityClass, (Collation) null);
+ return doFindOne(collectionName, CollectionPreparer.identity(), new Document(idKey, id), null, entityClass,
+ (Collation) null);
}
@Override
@@ -850,6 +861,7 @@ public Flux findDistinct(Query query, String field, String collectionName
Document mappedQuery = distinctQueryContext.getMappedQuery(entity);
String mappedFieldName = distinctQueryContext.getMappedFieldName(entity);
Class mongoDriverCompatibleType = distinctQueryContext.getDriverCompatibleClass(resultClass);
+ ReactiveCollectionPreparerDelegate collectionPreparer = ReactiveCollectionPreparerDelegate.of(query);
Flux> result = execute(collectionName, collection -> {
@@ -859,11 +871,9 @@ public Flux findDistinct(Query query, String field, String collectionName
}
FindPublisherPreparer preparer = new QueryFindPublisherPreparer(query, entityClass);
- if (preparer.hasReadPreference()) {
- collection = collection.withReadPreference(preparer.getReadPreference());
- }
- DistinctPublisher publisher = collection.distinct(mappedFieldName, mappedQuery, mongoDriverCompatibleType);
+ DistinctPublisher publisher = collectionPreparer.prepare(collection).distinct(mappedFieldName, mappedQuery,
+ mongoDriverCompatibleType);
distinctQueryContext.applyCollation(entityClass, publisher::collation);
return publisher;
});
@@ -929,7 +939,8 @@ private Flux aggregateAndMap(MongoCollection collection, List readCallback,
@Nullable Class> inputType) {
- AggregatePublisher cursor = collection.aggregate(pipeline, Document.class)
+ ReactiveCollectionPreparerDelegate collectionPreparer = ReactiveCollectionPreparerDelegate.of(options);
+ AggregatePublisher cursor = collectionPreparer.prepare(collection).aggregate(pipeline, Document.class)
.allowDiskUse(options.isAllowDiskUse());
if (options.getCursorBatchSize() != null) {
@@ -1028,8 +1039,8 @@ public Mono findAndModify(Query query, UpdateDefinition update, FindAndMo
operations.forType(entityClass).getCollation(query).ifPresent(optionsToUse::collation);
}
- return doFindAndModify(collectionName, query.getQueryObject(), query.getFieldsObject(),
- getMappedSortObject(query, entityClass), entityClass, update, optionsToUse);
+ return doFindAndModify(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
+ query.getFieldsObject(), getMappedSortObject(query, entityClass), entityClass, update, optionsToUse);
}
@Override
@@ -1053,6 +1064,7 @@ public Mono findAndReplace(Query query, S replacement, FindAndReplaceO
Document mappedQuery = queryContext.getMappedQuery(entity);
Document mappedFields = queryContext.getMappedFields(entity, projection);
Document mappedSort = queryContext.getMappedSort(entity);
+ ReactiveCollectionPreparerDelegate collectionPreparer = ReactiveCollectionPreparerDelegate.of(query);
return Mono.defer(() -> {
@@ -1070,8 +1082,9 @@ public Mono findAndReplace(Query query, S replacement, FindAndReplaceO
mapped.getCollection()));
}).flatMap(it -> {
- Mono afterFindAndReplace = doFindAndReplace(it.getCollection(), mappedQuery, mappedFields, mappedSort,
- queryContext.getCollation(entityType).orElse(null), entityType, it.getTarget(), options, projection);
+ Mono afterFindAndReplace = doFindAndReplace(it.getCollection(), collectionPreparer, mappedQuery,
+ mappedFields, mappedSort, queryContext.getCollation(entityType).orElse(null), entityType, it.getTarget(),
+ options, projection);
return afterFindAndReplace.flatMap(saved -> {
maybeEmitEvent(new AfterSaveEvent<>(saved, it.getTarget(), it.getCollection()));
return maybeCallAfterSave(saved, it.getTarget(), it.getCollection());
@@ -1089,9 +1102,9 @@ public Mono findAndRemove(Query query, Class entityClass) {
public Mono findAndRemove(Query query, Class entityClass, String collectionName) {
operations.forType(entityClass).getCollation(query);
- return doFindAndRemove(collectionName, query.getQueryObject(), query.getFieldsObject(),
- getMappedSortObject(query, entityClass), operations.forType(entityClass).getCollation(query).orElse(null),
- entityClass);
+ return doFindAndRemove(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
+ query.getFieldsObject(), getMappedSortObject(query, entityClass),
+ operations.forType(entityClass).getCollation(query).orElse(null), entityClass);
}
/*
@@ -1799,12 +1812,14 @@ protected Mono doRemove(String collectionName, Query query, @N
MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName, entityClass,
null, removeQuery);
WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction);
+ ReactiveCollectionPreparerDelegate collectionPreparer = ReactiveCollectionPreparerDelegate.of(query);
return execute(collectionName, collection -> {
maybeEmitEvent(new BeforeDeleteEvent<>(removeQuery, entityClass, collectionName));
- MongoCollection collectionToUse = prepareCollection(collection, writeConcernToUse);
+ MongoCollection collectionToUse = collectionPreparer
+ .prepare(prepareCollection(collection, writeConcernToUse));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Remove using query: %s in collection: %s.", serializeToJsonSafely(removeQuery),
@@ -1839,8 +1854,9 @@ public Flux findAll(Class entityClass) {
@Override
public Flux findAll(Class entityClass, String collectionName) {
- return executeFindMultiInternal(new FindCallback(null), FindPublisherPreparer.NO_OP_PREPARER,
- new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName), collectionName);
+ return executeFindMultiInternal(new FindCallback(CollectionPreparer.identity(), null),
+ FindPublisherPreparer.NO_OP_PREPARER, new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName),
+ collectionName);
}
@Override
@@ -1867,17 +1883,19 @@ public Flux