Class ReactiveMongoTemplate
- All Implemented Interfaces:
Aware,ApplicationContextAware,ReactiveAggregationOperation,ReactiveChangeStreamOperation,ReactiveFindOperation,ReactiveFluentMongoOperations,ReactiveInsertOperation,ReactiveMapReduceOperation,ReactiveMongoOperations,ReactiveRemoveOperation,ReactiveUpdateOperation
ReactiveMongoOperations. It simplifies the use of Reactive MongoDB usage and helps
to avoid common errors. It executes core MongoDB workflow, leaving application code to provide Document and
extract results. This class executes BSON queries or updates, initiating iteration over 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
ReactiveMongoDatabaseFactory reference, or get prepared in an application context and given to services as
bean reference.
Note: The 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.
ReadPreference and ReadConcern
ReadPreference and ReadConcern are generally considered from Query and
AggregationOptions objects for the action to be executed on a particular MongoCollection.
You can also set the default ReadPreference on the template level to
generally apply a ReadPreference.
When using transactions make sure to create this template with the same ReactiveMongoDatabaseFactory that is
also used for ReactiveMongoTransactionManager creation.
- Since:
- 2.0
- Author:
- Mark Paluch, Christoph Strobl, Roman Puchkovskiy, Mathieu Ouellet, Yadhukrishna S Pai, Florian Lüdiger
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveAggregationOperation
ReactiveAggregationOperation.AggregationOperationWithAggregation<T>, ReactiveAggregationOperation.AggregationOperationWithCollection<T>, ReactiveAggregationOperation.ReactiveAggregation<T>, ReactiveAggregationOperation.TerminatingAggregationOperation<T>Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveChangeStreamOperation
ReactiveChangeStreamOperation.ChangeStreamWithCollection<T>, ReactiveChangeStreamOperation.ChangeStreamWithFilterAndProjection<T>, ReactiveChangeStreamOperation.ChangeStreamWithOptions<T>, ReactiveChangeStreamOperation.ReactiveChangeStream<T>, ReactiveChangeStreamOperation.ResumingChangeStream<T>, ReactiveChangeStreamOperation.TerminatingChangeStream<T>Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveFindOperation
ReactiveFindOperation.DistinctWithProjection, ReactiveFindOperation.DistinctWithQuery<T>, ReactiveFindOperation.FindDistinct, ReactiveFindOperation.FindWithCollection<T>, ReactiveFindOperation.FindWithProjection<T>, ReactiveFindOperation.FindWithQuery<T>, ReactiveFindOperation.ReactiveFind<T>, ReactiveFindOperation.TerminatingDistinct<T>, ReactiveFindOperation.TerminatingFind<T>, ReactiveFindOperation.TerminatingFindNear<T>Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveInsertOperation
ReactiveInsertOperation.InsertWithCollection<T>, ReactiveInsertOperation.ReactiveInsert<T>, ReactiveInsertOperation.TerminatingInsert<T>Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveMapReduceOperation
ReactiveMapReduceOperation.MapReduceWithCollection<T>, ReactiveMapReduceOperation.MapReduceWithMapFunction<T>, ReactiveMapReduceOperation.MapReduceWithOptions<T>, ReactiveMapReduceOperation.MapReduceWithProjection<T>, ReactiveMapReduceOperation.MapReduceWithQuery<T>, ReactiveMapReduceOperation.MapReduceWithReduceFunction<T>, ReactiveMapReduceOperation.ReactiveMapReduce<T>, ReactiveMapReduceOperation.TerminatingMapReduce<T>Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveRemoveOperation
ReactiveRemoveOperation.ReactiveRemove<T>, ReactiveRemoveOperation.RemoveWithCollection<T>, ReactiveRemoveOperation.RemoveWithQuery<T>, ReactiveRemoveOperation.TerminatingRemove<T>Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveUpdateOperation
ReactiveUpdateOperation.FindAndModifyWithOptions<T>, ReactiveUpdateOperation.FindAndReplaceWithOptions<T>, ReactiveUpdateOperation.FindAndReplaceWithProjection<T>, ReactiveUpdateOperation.ReactiveUpdate<T>, ReactiveUpdateOperation.ReplaceWithOptions, ReactiveUpdateOperation.TerminatingFindAndModify<T>, ReactiveUpdateOperation.TerminatingFindAndReplace<T>, ReactiveUpdateOperation.TerminatingReplace, ReactiveUpdateOperation.TerminatingUpdate<T>, ReactiveUpdateOperation.UpdateWithCollection<T>, ReactiveUpdateOperation.UpdateWithQuery<T>, ReactiveUpdateOperation.UpdateWithUpdate<T> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReactiveMongoTemplate(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName) Constructor used for a basic template configuration.ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory) Constructor used for a basic template configuration.ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory, MongoConverter mongoConverter) Constructor used for a basic template configuration.ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory, MongoConverter mongoConverter, Consumer<Throwable> subscriptionExceptionHandler) Constructor used for a basic template configuration. -
Method Summary
Modifier and TypeMethodDescription<O> Flux<O>aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) Execute an aggregation operation.<O> Flux<O>aggregate(Aggregation aggregation, String collectionName, Class<O> outputType) Execute an aggregation operation.<O> Flux<O>aggregate(TypedAggregation<?> aggregation, Class<O> outputType) Execute an aggregation operation.<O> Flux<O>aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) Execute an aggregation operation.aggregateAndReturn(Class<T> domainType) Start creating an aggregation operation that returns results mapped to the given domain type.bulkOps(BulkOperations.BulkMode mode, Class<?> entityClass) Returns a newReactiveBulkOperationsfor the given entity type.bulkOps(BulkOperations.BulkMode mode, Class<?> entityType, String collectionName) Returns a newReactiveBulkOperationsfor the given entity type and collection name.bulkOps(BulkOperations.BulkMode mode, String collectionName) Returns a newReactiveBulkOperationsfor the given collection.changeStream(Class<T> domainType) Start creating a change stream operation for the given domainType watching all collections within the database.<T> Flux<ChangeStreamEvent<T>>changeStream(String database, String collectionName, ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream via the reactive infrastructure.collectionExists(Class<T> entityClass) Check to see if a collection with a name indicated by the entity class exists.collectionExists(String collectionName) Check to see if a collection with a given name exists.protected com.mongodb.client.model.CreateCollectionOptionsconvertToCreateCollectionOptions(CollectionOptions collectionOptions) protected com.mongodb.client.model.CreateCollectionOptionsconvertToCreateCollectionOptions(CollectionOptions collectionOptions, Class<?> entityType) Returns the number of documents for the givenQueryby querying the collection of the given entity class.Returns the number of documents for the givenQueryquerying the given collection.countCanBeEstimated(org.bson.Document filter, com.mongodb.client.model.CountOptions options) <T> Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>createCollection(Class<T> entityClass) Create an uncapped collection with a name based on the provided entity class.<T> Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>createCollection(Class<T> entityClass, CollectionOptions collectionOptions) Create a collection with a name based on the provided entity class using the options.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>createCollection(String collectionName) Create an uncapped collection with the provided name.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>createCollection(String collectionName, CollectionOptions collectionOptions) Create a collection with the provided name and options.<T> Flux<T>createFlux(String collectionName, ReactiveCollectionCallback<T> callback) <T> Flux<T>createFlux(ReactiveDatabaseCallback<T> callback) Create a reusable Flux for aReactiveDatabaseCallback.<T> Mono<T>createMono(String collectionName, ReactiveCollectionCallback<T> callback) <T> Mono<T>createMono(ReactiveDatabaseCallback<T> callback) Create a reusable Mono for aReactiveDatabaseCallback.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>createView(String name, Class<?> source, AggregationPipeline pipeline, ViewOptions options) Create a view with the provided name.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>createView(String name, String source, AggregationPipeline pipeline, ViewOptions options) Create a view with the provided name.protected <O> Flux<O>doAggregate(Aggregation aggregation, String collectionName, Class<?> inputType, Class<O> outputType) doCount(String collectionName, org.bson.Document filter, com.mongodb.client.model.CountOptions options) Run the actual count operation against the collection with given name.protected Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>doCreateCollection(String collectionName, com.mongodb.client.model.CreateCollectionOptions collectionOptions) Create the specified collection using the provided optionsprotected Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>doCreateView(String name, String source, List<org.bson.Document> pipeline, ViewOptions options) doEstimatedCount(String collectionName, com.mongodb.client.model.EstimatedDocumentCountOptions options) doExactCount(String collectionName, org.bson.Document filter, com.mongodb.client.model.CountOptions options) protected <S,T> Flux<T> doFind(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<S> entityClass, FindPublisherPreparer preparer, org.springframework.data.mongodb.core.ReactiveMongoTemplate.DocumentCallback<T> objectCallback) protected <T> Flux<T>doFind(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<T> entityClass) Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter.protected <T> Flux<T>doFind(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<T> entityClass, FindPublisherPreparer preparer) Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.protected <T> Flux<T>doFindAndDelete(String collectionName, Query query, Class<T> entityClass) Retrieve and remove all documents matching the givenqueryby callingfind(Query, Class, String)andremove(Query, Class, String), whereas theQueryforremove(Query, Class, String)is constructed out of the find result.protected <T> Mono<T>doFindAndModify(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, org.bson.Document sort, Class<T> entityClass, UpdateDefinition update, FindAndModifyOptions options) protected <T> Mono<T>doFindAndRemove(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, org.bson.Document sort, Collation collation, Class<T> entityClass) Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.protected <T> Mono<T>doFindAndReplace(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document mappedQuery, org.bson.Document mappedFields, org.bson.Document mappedSort, com.mongodb.client.model.Collation collation, Class<?> entityType, org.bson.Document replacement, FindAndReplaceOptions options, Class<T> resultType) Customize this part for findAndReplace.protected <T> Mono<T>doFindOne(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<T> entityClass, FindPublisherPreparer preparer) Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.protected <T> Mono<T>doFindOne(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<T> entityClass, Collation collation) Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.protected Mono<com.mongodb.reactivestreams.client.MongoDatabase>protected <T> Mono<T>doInsert(String collectionName, T objectToSave, MongoWriter<Object> writer) protected <T> Flux<T>doInsertAll(Collection<? extends T> listToSave, MongoWriter<Object> writer) protected <T> Flux<T>doInsertBatch(String collectionName, Collection<? extends T> batchToSave, MongoWriter<Object> writer) protected <T> Mono<com.mongodb.client.result.DeleteResult>protected <T> Mono<T>doSave(String collectionName, T objectToSave, MongoWriter<Object> writer) protected Mono<com.mongodb.client.result.UpdateResult>doUpdate(String collectionName, Query query, UpdateDefinition update, Class<?> entityClass, boolean upsert, boolean multi) dropCollection(Class<T> entityClass) Drop the collection with the name indicated by the entity class.dropCollection(String collectionName) Drop the collection with the given name.protected voidensureNotCollectionLike(Object source) estimatedCount(String collectionName) Estimate the number of documents in the given collection based on collection statistics.exactCount(Query query, Class<?> entityClass, String collectionName) <T> Flux<T>execute(Class<?> entityClass, ReactiveCollectionCallback<T> action) Executes the givenReactiveCollectionCallbackon the entity collection of the specified class.<T> Flux<T>execute(String collectionName, ReactiveCollectionCallback<T> callback) Executes the givenReactiveCollectionCallbackon the collection of the given name.<T> Flux<T>execute(ReactiveDatabaseCallback<T> action) Executes aReactiveDatabaseCallbacktranslating any exceptions as necessary.Mono<org.bson.Document>executeCommand(String jsonCommand) Execute a MongoDB command expressed as a JSON string.Mono<org.bson.Document>executeCommand(org.bson.Document command) Execute a MongoDB command.Mono<org.bson.Document>executeCommand(org.bson.Document command, com.mongodb.ReadPreference readPreference) Execute a MongoDB command.Determine result of givenQuerycontains at least one element.Determine result of givenQuerycontains at least one element.Determine result of givenQuerycontains at least one element.<T> Flux<T>Map the results of an ad-hoc query on the collection for the entity class to aFluxof the specified type.<T> Flux<T>Map the results of an ad-hoc query on the specified collection to aFluxof the specified type.<T> Flux<T>Query for aFluxof objects of type T from the collection used by the entity class.<T> Flux<T>Query for aFluxof objects of type T from the specified collection.<T> Flux<T>findAllAndRemove(Query query, Class<T> entityClass) Returns and removes all documents matching the given query form the collection used to store the entityClass.<T> Flux<T>findAllAndRemove(Query query, Class<T> entityClass, String collectionName) Returns and removes all documents that match the provided query document criteria from the collection used to store the entityClass.<T> Flux<T>findAllAndRemove(Query query, String collectionName) Returns and removes all documents form the specified collection that match the provided query.<T> Mono<T>findAndModify(Query query, UpdateDefinition update, Class<T> entityClass) <T> Mono<T>findAndModify(Query query, UpdateDefinition update, Class<T> entityClass, String collectionName) <T> Mono<T>findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass) Triggers findAndModify to apply providedUpdateon documents matchingCriteriaof givenQuerytakingFindAndModifyOptionsinto account.<T> Mono<T>findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass, String collectionName) Triggers findAndModify to apply providedUpdateon documents matchingCriteriaof givenQuerytakingFindAndModifyOptionsinto account.<T> Mono<T>findAndRemove(Query query, Class<T> entityClass) Map the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the specified type.<T> Mono<T>findAndRemove(Query query, Class<T> entityClass, String collectionName) Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type.<S,T> Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType, String collectionName, Class<T> resultType) Triggers findOneAndReplace to replace a single document matchingCriteriaof givenQuerywith thereplacementdocument takingFindAndReplaceOptionsinto account.<T> Mono<T>Returns a document with the given id mapped onto the given class.<T> Mono<T>Returns the document with the given id from the given collection mapped onto the given target class.<T> Flux<T>findDistinct(Query query, String field, Class<?> entityClass, Class<T> resultClass) Finds the distinct values for a specified field across a singleMongoCollectionor view and returns the results in aFlux.<T> Flux<T>findDistinct(Query query, String field, String collectionName, Class<?> entityClass, Class<T> resultClass) Finds the distinct values for a specified field across a singleMongoCollectionor view and returns the results in aFlux.<T> Mono<T>Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the specified type.<T> Mono<T>Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>getCollection(String collectionName) Get aMongoCollectionby name.getCollectionName(Class<?> entityClass) The collection name used for the specified class by this template.A set of collection names.Returns the defaultMongoConverter.Mono<com.mongodb.reactivestreams.client.MongoDatabase>Returns the reactive operations that can be performed on indexesReturns the reactive operations that can be performed on indexesStart creating an insert operation for given domainType.<T> Flux<T>insert(Collection<? extends T> batchToSave, Class<?> entityClass) Insert a Collection of objects into a collection in a single batch write to the database.<T> Flux<T>insert(Collection<? extends T> batchToSave, String collectionName) Insert a batch of objects into the specified collection in a single batch write to the database.<T> Mono<T>Insert the object into the collection for the entity type of the object to save.<T> Mono<T>insert(T objectToSave) Insert the object into the collection for the entity type of the object to save.<T> Mono<T>Insert the object into the specified collection.<T> Flux<T>insertAll(Collection<? extends T> objectsToSave) Insert a mixed Collection of objects into a database collection determining the collection name to use based on the class.<T> Flux<T>insertAll(Mono<? extends Collection<? extends T>> objectsToSave) Insert a mixed Collection of objects into a database collection determining the collection name to use based on the class.<T> Flux<T>insertAll(Mono<? extends Collection<? extends T>> batchToSave, Class<?> entityClass) Insert a Collection of objects into a collection in a single batch write to the database.<T> Flux<T>insertAll(Mono<? extends Collection<? extends T>> batchToSave, String collectionName) Insert objects into the specified collection in a single batch write to the database.insertDocument(String collectionName, org.bson.Document dbDoc, Class<?> entityClass) protected Flux<org.bson.types.ObjectId>insertDocumentList(String collectionName, List<org.bson.Document> dbDocList) Start creating a mapReduce operation for the given domainType.<T> Flux<T>mapReduce(Query filterQuery, Class<?> domainType, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Execute a map-reduce operation.<T> Flux<T>mapReduce(Query filterQuery, Class<?> domainType, String inputCollectionName, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Execute a map-reduce operation.protected <T> Mono<T>maybeCallAfterConvert(T object, org.bson.Document document, String collection) protected <T> Mono<T>maybeCallAfterSave(T object, org.bson.Document document, String collection) protected <T> Mono<T>maybeCallBeforeConvert(T object, String collection) protected <T> Mono<T>maybeCallBeforeSave(T object, org.bson.Document document, String collection) protected <E extends MongoMappingEvent<T>,T>
EmaybeEmitEvent(E event) protected com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>prepareCollection(com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> collection) Prepare the collection before any processing is done using it.protected com.mongodb.reactivestreams.client.MongoDatabaseprepareDatabase(com.mongodb.reactivestreams.client.MongoDatabase database) protected com.mongodb.WriteConcernprepareWriteConcern(MongoAction mongoAction) Prepare the WriteConcern before any processing is done using it.Start creating a find operation for the given domainType.Start creating a remove operation for the given domainType.Mono<com.mongodb.client.result.DeleteResult>Remove the given object from the collection by id and (if applicable) itsVersion.Mono<com.mongodb.client.result.DeleteResult>Removes the given object from the given collection.Mono<com.mongodb.client.result.DeleteResult>Remove all documents that match the provided query document criteria from the collection used to store the entityClass.Mono<com.mongodb.client.result.DeleteResult>Remove all documents that match the provided query document criteria from the collection used to store the entityClass.Mono<com.mongodb.client.result.DeleteResult>Remove all documents from the specified collection that match the provided query document criteria.Mono<com.mongodb.client.result.DeleteResult>Remove the given object from the collection by id and (if applicable) itsVersion.Mono<com.mongodb.client.result.DeleteResult>Removes the given object from the given collection by id and (if applicable) itsVersion.protected <S,T> Mono<com.mongodb.client.result.UpdateResult> replace(Query query, Class<S> entityType, T replacement, ReplaceOptions options, String collectionName) <T> Mono<com.mongodb.client.result.UpdateResult>replace(Query query, T replacement, ReplaceOptions options, String collectionName) Replace a single document matching theCriteriaof givenQuerywith thereplacementdocument takingReplaceOptionsinto account.<T> Mono<T>Save the object to the collection for the entity type of the object to save.<T> Mono<T>Save the object to the specified collection.<T> Mono<T>save(T objectToSave) Save the object to the collection for the entity type of the object to save.<T> Mono<T>Save the object to the specified collection.saveDocument(String collectionName, org.bson.Document document, Class<?> entityClass) Query for a scroll of objects of type T from the specified collection.Query for a window of objects of type T from the specified collection.voidsetApplicationContext(ApplicationContext applicationContext) voidsetEntityCallbacks(ReactiveEntityCallbacks entityCallbacks) Set theReactiveEntityCallbacksinstance to use when invokingcallbackslike theReactiveBeforeSaveCallback.voidsetEntityLifecycleEventsEnabled(boolean enabled) Configure whether lifecycle events such asAfterLoadEvent,BeforeSaveEvent, etc. should be published or whether emission should be suppressed.voidsetReadPreference(com.mongodb.ReadPreference readPreference) Used by {@link {@link #prepareCollection(MongoCollection)} to set theReadPreferencebefore any operations are performed.voidsetSessionSynchronization(SessionSynchronization sessionSynchronization) Define ifReactiveMongoTemplateshould participate in transactions.voidsetWriteConcern(com.mongodb.WriteConcern writeConcern) Configures theWriteConcernto be used with the template.voidsetWriteConcernResolver(WriteConcernResolver writeConcernResolver) Configures theWriteConcernResolverto be used with the template.voidsetWriteResultChecking(WriteResultChecking resultChecking) Configures theWriteResultCheckingto be used with the template.<T> Flux<T>Map the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified type.<T> Flux<T>Map the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified type.Start creating an update operation for the given domainType.Mono<com.mongodb.client.result.UpdateResult>updateFirst(Query query, UpdateDefinition update, Class<?> entityClass) Updates the first object that is found in the collection of the entity class that matches the query document with the provided update document.Mono<com.mongodb.client.result.UpdateResult>updateFirst(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.Mono<com.mongodb.client.result.UpdateResult>updateFirst(Query query, UpdateDefinition update, String collectionName) Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.Mono<com.mongodb.client.result.UpdateResult>updateMulti(Query query, UpdateDefinition update, Class<?> entityClass) Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.Mono<com.mongodb.client.result.UpdateResult>updateMulti(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.Mono<com.mongodb.client.result.UpdateResult>updateMulti(Query query, UpdateDefinition update, String collectionName) Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document.Mono<com.mongodb.client.result.UpdateResult>upsert(Query query, UpdateDefinition update, Class<?> entityClass) Performs an upsert.Mono<com.mongodb.client.result.UpdateResult>upsert(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Performs an upsert.Mono<com.mongodb.client.result.UpdateResult>upsert(Query query, UpdateDefinition update, String collectionName) Performs an upsert.voiduseEstimatedCount(boolean enabled) Configure whether to use estimated count.withSession(com.mongodb.ClientSessionOptions sessionOptions) Obtain asessionbound instance ofSessionScopedbinding a newClientSessionwith given sessionOptions to each and every command issued against MongoDB.withSession(com.mongodb.reactivestreams.client.ClientSession session) Obtain aClientSessionbound instance ofReactiveMongoOperations.withSession(Publisher<com.mongodb.reactivestreams.client.ClientSession> sessionProvider) Obtain asessionbound instance ofReactiveSessionScopedbinding theClientSessionprovided by the givenPublisherto each and every command issued against MongoDB.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.core.ReactiveMongoOperations
changeStream, changeStream, createView, createView, estimatedCount, exactCount, exactCount, findAndReplace, findAndReplace, findAndReplace, findAndReplace, findAndReplace, findAndReplace, findDistinct, findDistinct, replace, replace, replace, withSession
-
Field Details
-
NO_OP_REF_RESOLVER
-
-
Constructor Details
-
ReactiveMongoTemplate
public ReactiveMongoTemplate(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName) Constructor used for a basic template configuration.If you intend to use transactions, make sure to use
ReactiveMongoTemplate(ReactiveMongoDatabaseFactory)orReactiveMongoTemplate(ReactiveMongoDatabaseFactory, MongoConverter)constructors, otherwise, this template will not participate in transactions using the defaultSessionSynchronization.ON_ACTUAL_TRANSACTIONsetting asReactiveMongoTransactionManageruses strictly its configuredReactiveMongoDatabaseFactoryfor transaction participation.- Parameters:
mongoClient- must not be null.databaseName- must not be null or empty.
-
ReactiveMongoTemplate
Constructor used for a basic template configuration.- Parameters:
mongoDatabaseFactory- must not be null.
-
ReactiveMongoTemplate
public ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory, @Nullable MongoConverter mongoConverter) Constructor used for a basic template configuration.- Parameters:
mongoDatabaseFactory- must not be null.mongoConverter- can be null.
-
ReactiveMongoTemplate
public ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory, @Nullable MongoConverter mongoConverter, Consumer<Throwable> subscriptionExceptionHandler) Constructor used for a basic template configuration.- Parameters:
mongoDatabaseFactory- must not be null.mongoConverter- can be null.subscriptionExceptionHandler- exception handler called byFlux.doOnError(Consumer)on reactive type materialization viaPublisher.subscribe(Subscriber). This callback is used during non-blocking subscription of e.g. index creationPublishers. Must not be null.- Since:
- 2.1
-
-
Method Details
-
setWriteResultChecking
Configures theWriteResultCheckingto be used with the template. Setting null will reset the default ofDEFAULT_WRITE_RESULT_CHECKING.- Parameters:
resultChecking-
-
setWriteConcern
Configures theWriteConcernto be used with the template. If none is configured theWriteConcernconfigured on theMongoDatabaseFactorywill apply.- Parameters:
writeConcern- can be null.
-
setWriteConcernResolver
Configures theWriteConcernResolverto be used with the template.- Parameters:
writeConcernResolver- can be null.
-
setReadPreference
public void setReadPreference(com.mongodb.ReadPreference readPreference) Used by {@link {@link #prepareCollection(MongoCollection)} to set theReadPreferencebefore any operations are performed.- Parameters:
readPreference-
-
setEntityLifecycleEventsEnabled
public void setEntityLifecycleEventsEnabled(boolean enabled) Configure whether lifecycle events such asAfterLoadEvent,BeforeSaveEvent, etc. should be published or whether emission should be suppressed. Enabled by default.- Parameters:
enabled-trueto enable entity lifecycle events;falseto disable entity lifecycle events.- Since:
- 4.0
- See Also:
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
setEntityCallbacks
Set theReactiveEntityCallbacksinstance to use when invokingcallbackslike theReactiveBeforeSaveCallback.
Overrides potentially existingReactiveEntityCallbacks.- Parameters:
entityCallbacks- must not be null.- Throws:
IllegalArgumentException- if the given instance is null.- Since:
- 2.2
-
useEstimatedCount
public void useEstimatedCount(boolean enabled) Configure whether to use estimated count. Defaults to exact counting.- Parameters:
enabled- useMongoCollection.estimatedDocumentCount()for unpaged and emptyqueriesiftrue.- Since:
- 3.4
-
getConverter
Returns the defaultMongoConverter.- Specified by:
getConverterin interfaceReactiveMongoOperations- Returns:
-
indexOps
Description copied from interface:ReactiveMongoOperationsReturns the reactive operations that can be performed on indexes- Specified by:
indexOpsin interfaceReactiveMongoOperations- Parameters:
collectionName- must not be null.- Returns:
- index operations on the named collection
-
indexOps
Description copied from interface:ReactiveMongoOperationsReturns the reactive operations that can be performed on indexes- Specified by:
indexOpsin interfaceReactiveMongoOperations- Parameters:
entityClass- must not be null.- Returns:
- index operations on the named collection associated with the given entity class
-
getCollectionName
Description copied from interface:ReactiveMongoOperationsThe collection name used for the specified class by this template.- Specified by:
getCollectionNamein interfaceReactiveMongoOperations- Parameters:
entityClass- must not be null.- Returns:
- never null.
-
executeCommand
Description copied from interface:ReactiveMongoOperationsExecute a MongoDB command expressed as a JSON string. This will call the method JSON.parse that is part of the MongoDB driver to convert the JSON string to a Document. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.- Specified by:
executeCommandin interfaceReactiveMongoOperations- Parameters:
jsonCommand- a MongoDB command expressed as a JSON string.- Returns:
- a result object returned by the action
-
executeCommand
Description copied from interface:ReactiveMongoOperationsExecute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.- Specified by:
executeCommandin interfaceReactiveMongoOperations- Parameters:
command- a MongoDB command.- Returns:
- a result object returned by the action
-
executeCommand
public Mono<org.bson.Document> executeCommand(org.bson.Document command, @Nullable com.mongodb.ReadPreference readPreference) Description copied from interface:ReactiveMongoOperationsExecute a MongoDB command. Any errors that result from executing this command will be converted into Spring's data access exception hierarchy.- Specified by:
executeCommandin interfaceReactiveMongoOperations- Parameters:
command- a MongoDB command, must not be null.readPreference- read preferences to use, can be null.- Returns:
- a result object returned by the action.
-
execute
Description copied from interface:ReactiveMongoOperationsExecutes the givenReactiveCollectionCallbackon the entity collection of the specified class.
Allows for returning a result object, that is a domain object or a collection of domain objects.- Specified by:
executein interfaceReactiveMongoOperations- Type Parameters:
T- return type.- Parameters:
entityClass- class that determines the collection to use. Must not be null.action- callback object that specifies the MongoDB action. Must not be null.- Returns:
- a result object returned by the action or null.
-
execute
Description copied from interface:ReactiveMongoOperationsExecutes aReactiveDatabaseCallbacktranslating any exceptions as necessary.
Allows for returning a result object, that is a domain object or a collection of domain objects.- Specified by:
executein interfaceReactiveMongoOperations- Type Parameters:
T- return type.- Parameters:
action- callback object that specifies the MongoDB actions to perform on the passed in DB instance. Must not be null.- Returns:
- a result object returned by the action
-
execute
Description copied from interface:ReactiveMongoOperationsExecutes the givenReactiveCollectionCallbackon the collection of the given name.
Allows for returning a result object, that is a domain object or a collection of domain objects.- Specified by:
executein interfaceReactiveMongoOperations- Type Parameters:
T- return type.- Parameters:
collectionName- the name of the collection that specifies whichMongoCollectioninstance will be passed into. Must not be null or empty.callback- callback object that specifies the MongoDB action the callback action. Must not be null.- Returns:
- a result object returned by the action or null.
-
withSession
public ReactiveSessionScoped withSession(Publisher<com.mongodb.reactivestreams.client.ClientSession> sessionProvider) Description copied from interface:ReactiveMongoOperationsObtain asessionbound instance ofReactiveSessionScopedbinding theClientSessionprovided by the givenPublisherto each and every command issued against MongoDB.
Note: It is up to the caller to manage theClientSessionlifecycle. UseReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer)to provide a hook for processing theClientSessionwhen done.- Specified by:
withSessionin interfaceReactiveMongoOperations- Parameters:
sessionProvider- must not be null.- Returns:
- new instance of
ReactiveSessionScoped. Never null.
-
setSessionSynchronization
Define ifReactiveMongoTemplateshould participate in transactions. Default is set toSessionSynchronization.ON_ACTUAL_TRANSACTION.NOTE: MongoDB transactions require at least MongoDB 4.0.
- Since:
- 2.2
-
withSession
public ReactiveMongoOperations withSession(com.mongodb.reactivestreams.client.ClientSession session) Description copied from interface:ReactiveMongoOperationsObtain aClientSessionbound instance ofReactiveMongoOperations.
Note: It is up to the caller to manage theClientSessionlifecycle.- Specified by:
withSessionin interfaceReactiveMongoOperations- Returns:
ClientSessionbound instance ofReactiveMongoOperations.
-
withSession
Description copied from interface:ReactiveMongoOperationsObtain asessionbound instance ofSessionScopedbinding a newClientSessionwith given sessionOptions to each and every command issued against MongoDB.
Note: It is up to the caller to manage theClientSessionlifecycle. UseReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer)to provide a hook for processing theClientSessionwhen done.- Specified by:
withSessionin interfaceReactiveMongoOperations- Parameters:
sessionOptions- must not be null.- Returns:
- new instance of
ReactiveSessionScoped. Never null.
-
createFlux
Create a reusable Flux for aReactiveDatabaseCallback. It's up to the developer to choose to obtain a newFluxor to reuse theFlux.- Parameters:
callback- must not be null- Returns:
- a
Fluxwrapping theReactiveDatabaseCallback.
-
createMono
Create a reusable Mono for aReactiveDatabaseCallback. It's up to the developer to choose to obtain a newFluxor to reuse theFlux.- Parameters:
callback- must not be null- Returns:
- a
Monowrapping theReactiveDatabaseCallback.
-
createFlux
- Parameters:
collectionName- must not be empty or null.callback- must not be null.- Returns:
- a reusable
Fluxwrapping theReactiveCollectionCallback.
-
createMono
- Type Parameters:
T-- Parameters:
collectionName- must not be empty or null.callback- must not be null.- Returns:
- a reusable
Monowrapping theReactiveCollectionCallback.
-
createCollection
public <T> Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(Class<T> entityClass) Description copied from interface:ReactiveMongoOperationsCreate an uncapped collection with a name based on the provided entity class.This method derives
CollectionOptionsfrom the givenentityClassusingDocumentandTimeSeriesannotations to determine:- Collation
- TimeSeries time and meta fields, granularity and
expireAfter
ReactiveMongoOperations.createCollection(Class, CollectionOptions)orReactiveMongoOperations.createCollection(String, CollectionOptions).- Specified by:
createCollectionin interfaceReactiveMongoOperations- Parameters:
entityClass- class that determines the collection to create.- Returns:
- the created collection.
- See Also:
-
createCollection
public <T> Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(Class<T> entityClass, @Nullable CollectionOptions collectionOptions) Description copied from interface:ReactiveMongoOperationsCreate a collection with a name based on the provided entity class using the options.- Specified by:
createCollectionin interfaceReactiveMongoOperations- Parameters:
entityClass- class that determines the collection to create. Must not be null.collectionOptions- options to use when creating the collection.- Returns:
- the created collection.
-
createCollection
public Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(String collectionName) Description copied from interface:ReactiveMongoOperationsCreate an uncapped collection with the provided name.- Specified by:
createCollectionin interfaceReactiveMongoOperations- Parameters:
collectionName- name of the collection.- Returns:
- the created collection.
-
createCollection
public Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(String collectionName, @Nullable CollectionOptions collectionOptions) Description copied from interface:ReactiveMongoOperationsCreate a collection with the provided name and options.- Specified by:
createCollectionin interfaceReactiveMongoOperations- Parameters:
collectionName- name of the collection. Must not be null nor empty.collectionOptions- options to use when creating the collection.- Returns:
- the created collection.
-
createView
public Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, Class<?> source, AggregationPipeline pipeline, @Nullable ViewOptions options) Description copied from interface:ReactiveMongoOperationsCreate a view with the provided name. The view content is defined by thepipelineon another collection or view identified by the givensource type.- Specified by:
createViewin interfaceReactiveMongoOperations- Parameters:
name- the name of the view to create.source- the type defining the views source collection.pipeline- theAggregationPipelinedefining the view content.options- additional settings to apply when creating the view. Can be null.
-
createView
public Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, String source, AggregationPipeline pipeline, @Nullable ViewOptions options) Description copied from interface:ReactiveMongoOperationsCreate a view with the provided name. The view content is defined by thepipelineon another collection or view identified by the given source.- Specified by:
createViewin interfaceReactiveMongoOperations- Parameters:
name- the name of the view to create.source- the name of the collection or view defining the to be created views source.pipeline- theAggregationPipelinedefining the view content.options- additional settings to apply when creating the view. Can be null.
-
doCreateView
-
getCollection
public Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> getCollection(String collectionName) Description copied from interface:ReactiveMongoOperationsGet aMongoCollectionby name. The returned collection may not exists yet (except in local memory) and is created on first interaction with the server. Collections can be explicitly created viaReactiveMongoOperations.createCollection(Class). Please make sure to check if the collectionexistsfirst.
Translate any exceptions as necessary.- Specified by:
getCollectionin interfaceReactiveMongoOperations- Parameters:
collectionName- name of the collection.- Returns:
- an existing collection or one created on first server interaction.
-
collectionExists
Description copied from interface:ReactiveMongoOperationsCheck to see if a collection with a name indicated by the entity class exists.
Translate any exceptions as necessary.- Specified by:
collectionExistsin interfaceReactiveMongoOperations- Parameters:
entityClass- class that determines the name of the collection. Must not be null.- Returns:
- true if a collection with the given name is found, false otherwise.
-
collectionExists
Description copied from interface:ReactiveMongoOperationsCheck to see if a collection with a given name exists.
Translate any exceptions as necessary.- Specified by:
collectionExistsin interfaceReactiveMongoOperations- Parameters:
collectionName- name of the collection. Must not be null.- Returns:
- true if a collection with the given name is found, false otherwise.
-
dropCollection
Description copied from interface:ReactiveMongoOperationsDrop the collection with the name indicated by the entity class.
Translate any exceptions as necessary.- Specified by:
dropCollectionin interfaceReactiveMongoOperations- Parameters:
entityClass- class that determines the collection to drop/delete. Must not be null.
-
dropCollection
Description copied from interface:ReactiveMongoOperationsDrop the collection with the given name.
Translate any exceptions as necessary.- Specified by:
dropCollectionin interfaceReactiveMongoOperations- Parameters:
collectionName- name of the collection to drop/delete.
-
bulkOps
Description copied from interface:ReactiveMongoOperationsReturns a newReactiveBulkOperationsfor the given collection.
NOTE: Any additional support for field mapping, etc. is not available for update or remove operations in bulk mode due to the lack of domain type information. UseReactiveMongoOperations.bulkOps(BulkMode, Class, String)to get full type specific support.- Specified by:
bulkOpsin interfaceReactiveMongoOperations- Parameters:
mode- theBulkOperations.BulkModeto use for bulk operations, must not be null.collectionName- the name of the collection to work on, must not be null or empty.- Returns:
ReactiveBulkOperationson the named collection
-
bulkOps
Description copied from interface:ReactiveMongoOperationsReturns a newReactiveBulkOperationsfor the given entity type.- Specified by:
bulkOpsin interfaceReactiveMongoOperations- Parameters:
mode- theBulkOperations.BulkModeto use for bulk operations, must not be null.entityClass- the name of the entity class, must not be null.- Returns:
ReactiveBulkOperationson the named collection associated of the given entity class.
-
bulkOps
public ReactiveBulkOperations bulkOps(BulkOperations.BulkMode mode, @Nullable Class<?> entityType, String collectionName) Description copied from interface:ReactiveMongoOperationsReturns a newReactiveBulkOperationsfor the given entity type and collection name.- Specified by:
bulkOpsin interfaceReactiveMongoOperations- Parameters:
mode- theBulkOperations.BulkModeto use for bulk operations, must not be null.entityType- the name of the entity class. Can be null.collectionName- the name of the collection to work on, must not be null or empty.- Returns:
ReactiveBulkOperationson the named collection associated with the given entity class.
-
getCollectionNames
Description copied from interface:ReactiveMongoOperationsA set of collection names.- Specified by:
getCollectionNamesin interfaceReactiveMongoOperations- Returns:
- Flux of collection names.
-
getMongoDatabase
-
doGetDatabase
-
findOne
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the specified type.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
findOnein interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass- the parametrized type of the returnedMono.- Returns:
- the converted object.
-
findOne
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
findOnein interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass- the parametrized type of the returnedMono.collectionName- name of the collection to retrieve the objects from.- Returns:
- the converted object.
-
exists
Description copied from interface:ReactiveMongoOperationsDetermine result of givenQuerycontains at least one element.- Specified by:
existsin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find a document.entityClass- the parametrized type.- Returns:
- true if the query yields a result.
-
exists
Description copied from interface:ReactiveMongoOperationsDetermine result of givenQuerycontains at least one element.
NOTE: Any additional support for query/field mapping, etc. is not available due to the lack of domain type information. UseReactiveMongoOperations.exists(Query, Class, String)to get full type specific support.- Specified by:
existsin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find a document.collectionName- name of the collection to check for objects.- Returns:
- true if the query yields a result.
-
exists
Description copied from interface:ReactiveMongoOperationsDetermine result of givenQuerycontains at least one element.- Specified by:
existsin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find a document.entityClass- the parametrized type. Can be null.collectionName- name of the collection to check for objects.- Returns:
- true if the query yields a result.
-
find
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the collection for the entity class to aFluxof the specified type.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
findin interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification. Must not be null.entityClass- the parametrized type of the returnedFlux. Must not be null.- Returns:
- the
Fluxof converted objects.
-
find
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the specified collection to aFluxof the specified type.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
findin interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification. Must not be null.entityClass- the parametrized type of the returnedFlux.collectionName- name of the collection to retrieve the objects from. Must not be null.- Returns:
- the
Fluxof converted objects.
-
scroll
Description copied from interface:ReactiveMongoOperationsQuery for a scroll of objects of type T from the specified collection.
Make sure to either setQuery.skip(long)orQuery.with(KeysetScrollPosition)along withQuery.limit(int)to limit large query results for efficient scrolling.
Result objects are converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way to map objects since the test for class type is done in the client and not on the server.When using
KeysetScrollPosition, make sure to use non-nullablesort propertiesas MongoDB does not support criteria to reconstruct a query result from absent document fields ornullvalues through$gt/$ltoperators.- Specified by:
scrollin interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification. Must not be null.entityType- the parametrized type of the returned list.- Returns:
Monoemitting the converted window.- See Also:
-
scroll
Description copied from interface:ReactiveMongoOperationsQuery for a window of objects of type T from the specified collection.
Make sure to either setQuery.skip(long)orQuery.with(KeysetScrollPosition)along withQuery.limit(int)to limit large query results for efficient scrolling.
Result objects are converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way to map objects since the test for class type is done in the client and not on the server.When using
KeysetScrollPosition, make sure to use non-nullablesort propertiesas MongoDB does not support criteria to reconstruct a query result from absent document fields ornullvalues through$gt/$ltoperators.- Specified by:
scrollin interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification. Must not be null.entityType- the parametrized type of the returned list.collectionName- name of the collection to retrieve the objects from.- Returns:
Monoemitting the converted window.- See Also:
-
findById
Description copied from interface:ReactiveMongoOperationsReturns a document with the given id mapped onto the given class. The collection the query is ran against will be derived from the given target class as well.- Specified by:
findByIdin interfaceReactiveMongoOperations- Parameters:
id- the id of the document to return. Must not be null.entityClass- the type the document shall be converted into. Must not be null.- Returns:
- the document with the given id mapped onto the given target class.
-
findById
Description copied from interface:ReactiveMongoOperationsReturns the document with the given id from the given collection mapped onto the given target class.- Specified by:
findByIdin interfaceReactiveMongoOperations- Parameters:
id- the id of the document to return.entityClass- the type to convert the document to.collectionName- the collection to query for the document.- Returns:
- the converted object.
-
findDistinct
public <T> Flux<T> findDistinct(Query query, String field, Class<?> entityClass, Class<T> resultClass) Description copied from interface:ReactiveMongoOperationsFinds the distinct values for a specified field across a singleMongoCollectionor view and returns the results in aFlux.- Specified by:
findDistinctin interfaceReactiveMongoOperations- Parameters:
query- filterQueryto restrict search. Must not be null.field- the name of the field to inspect for distinct values. Must not be null.entityClass- the domain type used for determining the actualMongoCollectionand mapping theQueryto the domain type fields. Must not be null.resultClass- the result type. Must not be null.- Returns:
- never null.
-
findDistinct
public <T> Flux<T> findDistinct(Query query, String field, String collectionName, Class<?> entityClass, Class<T> resultClass) Description copied from interface:ReactiveMongoOperationsFinds the distinct values for a specified field across a singleMongoCollectionor view and returns the results in aFlux.- Specified by:
findDistinctin interfaceReactiveMongoOperations- Parameters:
query- filterQueryto restrict search. Must not be null.field- the name of the field to inspect for distinct values. Must not be null.collectionName- the explicit name of the actualMongoCollection. Must not be null.entityClass- the domain type used for mapping theQueryto the domain type fields.resultClass- the result type. Must not be null.- Returns:
- never null.
-
aggregate
public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) Description copied from interface:ReactiveMongoOperationsExecute an aggregation operation.The raw results will be mapped to the given entity class.
Aggregation streaming cannot be used with
aggregation explainnor withAggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size causeIllegalArgumentException.- Specified by:
aggregatein interfaceReactiveMongoOperations- Parameters:
aggregation- TheTypedAggregationspecification holding the aggregation operations. Must not be null.inputCollectionName- The name of the input collection to use for the aggregation. Must not be null.outputType- The parametrized type of the returnedFlux. Must not be null.- Returns:
- The results of the aggregation operation.
-
aggregate
Description copied from interface:ReactiveMongoOperationsExecute an aggregation operation.
The raw results will be mapped to the given entity class and are returned as stream. The name of the inputCollection is derived from theaggregation input type.
Aggregation streaming cannot be used withaggregation explainnor withAggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size causeIllegalArgumentException.- Specified by:
aggregatein interfaceReactiveMongoOperations- Parameters:
aggregation- TheTypedAggregationspecification holding the aggregation operations. Must not be null.outputType- The parametrized type of the returnedFlux. Must not be null.- Returns:
- The results of the aggregation operation.
-
aggregate
Description copied from interface:ReactiveMongoOperationsExecute an aggregation operation.
The raw results will be mapped to the givenouputType. The name of the inputCollection is derived from theinputType.
Aggregation streaming cannot be used withaggregation explainnor withAggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size causeIllegalArgumentException.- Specified by:
aggregatein interfaceReactiveMongoOperations- Parameters:
aggregation- TheAggregationspecification holding the aggregation operations. Must not be null.inputType- the inputType where the aggregation operation will read from. Must not be null.outputType- The parametrized type of the returnedFlux. Must not be null.- Returns:
- The results of the aggregation operation.
-
aggregate
Description copied from interface:ReactiveMongoOperationsExecute an aggregation operation.
The raw results will be mapped to the given entity class.
Aggregation streaming cannot be used withaggregation explainnor withAggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size causeIllegalArgumentException.- Specified by:
aggregatein interfaceReactiveMongoOperations- Parameters:
aggregation- TheAggregationspecification holding the aggregation operations. Must not be null.collectionName- the collection where the aggregation operation will read from. Must not be null or empty.outputType- The parametrized type of the returnedFlux. Must not be null.- Returns:
- The results of the aggregation operation.
-
doAggregate
-
geoNear
Description copied from interface:ReactiveMongoOperationsReturnsFluxofGeoResultfor all entities matching the givenNearQuery. Will consider entity mapping information to determine the collection the query is ran against. Note, that MongoDB limits the number of results by default. Make sure to add an explicit limit to theNearQueryif you expect a particular number of results.MongoDB 4.2 has removed the
geoNearcommand. This method uses since version 2.2 aggregations and the$geoNearaggregation command to emulategeoNearcommand functionality. We recommend using aggregations directly:TypedAggregation<T> geoNear = TypedAggregation.newAggregation(entityClass, Aggregation.geoNear(near, "dis")) .withOptions(AggregationOptions.builder().collation(near.getCollation()).build()); Flux<Document> results = aggregate(geoNear, Document.class);- Specified by:
geoNearin interfaceReactiveMongoOperations- Parameters:
near- must not be null.entityClass- must not be null.- Returns:
- the converted
GeoResults.
-
geoNear
Description copied from interface:ReactiveMongoOperationsReturnsFluxofGeoResultfor all entities matching the givenNearQuery. Note, that MongoDB limits the number of results by default. Make sure to add an explicit limit to theNearQueryif you expect a particular number of results.MongoDB 4.2 has removed the
geoNearcommand. This method uses since version 2.2 aggregations and the$geoNearaggregation command to emulategeoNearcommand functionality. We recommend using aggregations directly:TypedAggregation<T> geoNear = TypedAggregation.newAggregation(entityClass, Aggregation.geoNear(near, "dis")) .withOptions(AggregationOptions.builder().collation(near.getCollation()).build()); Flux<Document> results = aggregate(geoNear, Document.class);- Specified by:
geoNearin interfaceReactiveMongoOperations- Parameters:
near- must not be null.entityClass- must not be null.collectionName- the collection to trigger the query against. If no collection name is given the entity class will be inspected.- Returns:
- the converted
GeoResults.
-
geoNear
-
findAndModify
Description copied from interface:ReactiveMongoOperationsTriggers findAndModify to apply providedUpdateon documents matchingCriteriaof givenQuery.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
findAndModifyin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies theCriteriaused to find a document and also an optional fields specification. Must not be null.update- theUpdateDefinitionto apply on matching documents. Must not be null.entityClass- the parametrized type. Must not be null.- Returns:
- the converted object that was updated before it was updated.
- See Also:
-
findAndModify
public <T> Mono<T> findAndModify(Query query, UpdateDefinition update, Class<T> entityClass, String collectionName) Description copied from interface:ReactiveMongoOperationsTriggers findAndModify to apply providedUpdateon documents matchingCriteriaof givenQuery.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
findAndModifyin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies theCriteriaused to find a document and also an optional fields specification. Must not be null.update- theUpdateDefinitionto apply on matching documents. Must not be null.entityClass- the parametrized type. Must not be null.collectionName- the collection to query. Must not be null.- Returns:
- the converted object that was updated before it was updated.
- See Also:
-
findAndModify
public <T> Mono<T> findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass) Description copied from interface:ReactiveMongoOperationsTriggers findAndModify to apply providedUpdateon documents matchingCriteriaof givenQuerytakingFindAndModifyOptionsinto account.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
findAndModifyin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies theCriteriaused to find a document and also an optional fields specification.update- theUpdateDefinitionto apply on matching documents.options- theFindAndModifyOptionsholding additional information.entityClass- the parametrized type.- Returns:
- the converted object that was updated. Depending on the value of
FindAndModifyOptions.isReturnNew()this will either be the object as it was before the update or as it is after the update. - See Also:
-
findAndModify
public <T> Mono<T> findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass, String collectionName) Description copied from interface:ReactiveMongoOperationsTriggers findAndModify to apply providedUpdateon documents matchingCriteriaof givenQuerytakingFindAndModifyOptionsinto account.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
findAndModifyin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies theCriteriaused to find a document and also an optional fields specification. Must not be null.update- theUpdateDefinitionto apply on matching documents. Must not be null.options- theFindAndModifyOptionsholding additional information. Must not be null.entityClass- the parametrized type. Must not be null.collectionName- the collection to query. Must not be null.- Returns:
- the converted object that was updated. Depending on the value of
FindAndModifyOptions.isReturnNew()this will either be the object as it was before the update or as it is after the update. - See Also:
-
findAndReplace
public <S,T> Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType, String collectionName, Class<T> resultType) Description copied from interface:ReactiveMongoOperationsTriggers findOneAndReplace to replace a single document matchingCriteriaof givenQuerywith thereplacementdocument takingFindAndReplaceOptionsinto account.
NOTE: The replacement entity must not hold an id.- Specified by:
findAndReplacein interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies theCriteriaused to find a document and also an optional fields specification. Must not be null.replacement- the replacement document. Must not be null.options- theFindAndModifyOptionsholding additional information. Must not be null.entityType- the type used for mapping theQueryto domain type fields and deriving the collection from. Must not be null.collectionName- the collection to query. Must not be null.resultType- resultType the parametrized type projection return type. Must not be null, use the domain type ofObject.classinstead.- Returns:
- the converted object that was updated or
Mono.empty(), if not found. Depending on the value ofFindAndReplaceOptions.isReturnNew()this will either be the object as it was before the update or as it is after the update.
-
findAndRemove
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the specified type. The first document that matches the query is returned and also removed from the collection in the database.
The object is converted from the MongoDB native representation using an instance of .
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
findAndRemovein interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass- the parametrized type of the returnedMono.- Returns:
- the converted object
-
findAndRemove
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. The first document that matches the query is returned and also removed from the collection in the database.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
findAndRemovein interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass- the parametrized type of the returnedMono.collectionName- name of the collection to retrieve the objects from.- Returns:
- the converted object.
-
count
Description copied from interface:ReactiveMongoOperationsReturns the number of documents for the givenQueryby querying the collection of the given entity class.
NOTE: Queryoffsetandlimitcan have direct influence on the resulting number of documents found as those values are passed on to the server and potentially limit the range and order within which the server performs the count operation. Use an unpaged query to count all matches.
This method may choose to useReactiveMongoOperations.estimatedCount(Class)for empty queries instead of running anaggregation executionwhich may have an impact on performance.- Specified by:
countin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find documents. Must not be null.entityClass- class that determines the collection to use. Must not be null.- Returns:
- the count of matching documents.
- See Also:
-
count
Description copied from interface:ReactiveMongoOperationsReturns the number of documents for the givenQueryquerying the given collection. The givenQuerymust solely consist of document field references as we lack type information to map potential property references onto document fields. UseReactiveMongoOperations.count(Query, Class, String)to get full type specific support.
NOTE: Queryoffsetandlimitcan have direct influence on the resulting number of documents found as those values are passed on to the server and potentially limit the range and order within which the server performs the count operation. Use an unpaged query to count all matches.
This method may choose to useReactiveMongoOperations.estimatedCount(Class)for empty queries instead of running anaggregation executionwhich may have an impact on performance.- Specified by:
countin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find documents.collectionName- must not be null or empty.- Returns:
- the count of matching documents.
- See Also:
-
count
Description copied from interface:ReactiveMongoOperationsReturns the number of documents for the givenQueryby querying the given collection using the given entity class to map the givenQuery.
NOTE: Queryoffsetandlimitcan have direct influence on the resulting number of documents found as those values are passed on to the server and potentially limit the range and order within which the server performs the count operation. Use an unpaged query to count all matches.
This method may choose to useReactiveMongoOperations.estimatedCount(Class)for empty queries instead of running anaggregation executionwhich may have an impact on performance.- Specified by:
countin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find documents. Must not be null.entityClass- the parametrized type. Can be null.collectionName- must not be null or empty.- Returns:
- the count of matching documents.
- See Also:
-
doCount
protected Mono<Long> doCount(String collectionName, org.bson.Document filter, com.mongodb.client.model.CountOptions options) Run the actual count operation against the collection with given name.- Parameters:
collectionName- the name of the collection to count matching documents in.filter- the filter to apply. Must not be null.options- options to apply. Like collation and the such.- Returns:
-
estimatedCount
Description copied from interface:ReactiveMongoOperationsEstimate the number of documents in the given collection based on collection statistics.
Please make sure to read the MongoDB reference documentation about limitations on eg. sharded cluster or inside transactions.- Specified by:
estimatedCountin interfaceReactiveMongoOperations- Parameters:
collectionName- must not be null.- Returns:
- a
Monoemitting the estimated number of documents.
-
doEstimatedCount
-
exactCount
Description copied from interface:ReactiveMongoOperationsReturns the number of documents for the givenQueryby querying the given collection using the given entity class to map the givenQuery.
NOTE: Queryoffsetandlimitcan have direct influence on the resulting number of documents found as those values are passed on to the server and potentially limit the range and order within which the server performs the count operation. Use an unpaged query to count all matches.
This method uses anaggregation executioneven for emptyquerieswhich may have an impact on performance, but guarantees shard, session and transaction compliance. In case an inaccurate count satisfies the applications needs useReactiveMongoOperations.estimatedCount(String)for empty queries instead.- Specified by:
exactCountin interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies the criteria used to find documents. Must not be null.entityClass- the parametrized type. Can be null.collectionName- must not be null or empty.- Returns:
- the count of matching documents.
-
doExactCount
-
countCanBeEstimated
-
insert
Description copied from interface:ReactiveMongoOperationsInsert the object into the collection for the entity type of the object to save.
The object is converted to the MongoDB native representation using an instance of .
If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See Spring's Type Conversion" for more details.
Insert is used to initially store the object into the database. To update an existing object use the save method.A potential
Versionthe property will be auto incremented. The operation raises an error in case the document has been modified in between.- Specified by:
insertin interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collection. Must not be null.- Returns:
- the inserted objects.
-
insertAll
public <T> Flux<T> insertAll(Mono<? extends Collection<? extends T>> batchToSave, Class<?> entityClass) Description copied from interface:ReactiveMongoOperationsInsert a Collection of objects into a collection in a single batch write to the database.If an object within the batch has an Id property which holds a null value, it will be set with the generated Id from MongoDB.
Inserting new objects will trigger
Versionproperty initialization.- Specified by:
insertAllin interfaceReactiveMongoOperations- Parameters:
batchToSave- the publisher which provides objects to save. Must not be null.entityClass- class that determines the collection to use. Must not be null.- Returns:
- the inserted objects.
-
insertAll
public <T> Flux<T> insertAll(Mono<? extends Collection<? extends T>> batchToSave, String collectionName) Description copied from interface:ReactiveMongoOperationsInsert objects into the specified collection in a single batch write to the database.If an object within the batch has an Id property which holds a null value, it will be set with the generated Id from MongoDB.
Inserting new objects will trigger
Versionproperty initialization.- Specified by:
insertAllin interfaceReactiveMongoOperations- Parameters:
batchToSave- the publisher which provides objects to save. Must not be null.collectionName- name of the collection to store the object in. Must not be null.- Returns:
- the inserted objects.
-
insert
Description copied from interface:ReactiveMongoOperationsInsert the object into the collection for the entity type of the object to save.
The object is converted to the MongoDB native representation using an instance of .
If your object has an Id property which holds a null value, it will be set with the generated Id from MongoDB. If your Id property is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See Spring's Type Conversion" for more details.
Insert is used to initially store the object into the database. To update an existing object use the save method.Inserting new objects will trigger
Versionproperty initialization.The
objectToSavemust not be collection-like.- Specified by:
insertin interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collection. Must not be null.- Returns:
- the inserted object.
-
insert
Description copied from interface:ReactiveMongoOperationsInsert the object into the specified collection.
The object is converted to the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
Insert is used to initially store the object into the database. To update an existing object use the save method.Inserting new objects will trigger
Versionproperty initialization.The
objectToSavemust not be collection-like.- Specified by:
insertin interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collection. Must not be null.collectionName- name of the collection to store the object in. Must not be null.- Returns:
- the inserted object.
-
doInsert
-
insert
Description copied from interface:ReactiveMongoOperationsInsert a Collection of objects into a collection in a single batch write to the database.If an object within the batch has an Id property which holds a null value, it will be set with the generated Id from MongoDB.
Inserting new objects will trigger
Versionproperty initialization.- Specified by:
insertin interfaceReactiveMongoOperations- Parameters:
batchToSave- the batch of objects to save. Must not be null.entityClass- class that determines the collection to use. Must not be null.- Returns:
- the inserted objects.
-
insert
Description copied from interface:ReactiveMongoOperationsInsert a batch of objects into the specified collection in a single batch write to the database.If an object within the batch has an Id property which holds a null value, it will be set with the generated Id from MongoDB.
Inserting new objects will trigger
Versionproperty initialization.- Specified by:
insertin interfaceReactiveMongoOperations- Parameters:
batchToSave- the list of objects to save. Must not be null.collectionName- name of the collection to store the object in. Must not be null.- Returns:
- the inserted objects.
-
insertAll
Description copied from interface:ReactiveMongoOperationsInsert a mixed Collection of objects into a database collection determining the collection name to use based on the class.If an object within the batch has an Id property which holds a null value, it will be set with the generated Id from MongoDB.
Inserting new objects will trigger
Versionproperty initialization.- Specified by:
insertAllin interfaceReactiveMongoOperations- Parameters:
objectsToSave- the list of objects to save. Must not be null.- Returns:
- the saved objects.
-
insertAll
Description copied from interface:ReactiveMongoOperationsInsert a mixed Collection of objects into a database collection determining the collection name to use based on the class.If an object within the batch has an Id property which holds a null value, it will be set with the generated Id from MongoDB.
Inserting new objects will trigger
Versionproperty initialization.- Specified by:
insertAllin interfaceReactiveMongoOperations- Parameters:
objectsToSave- the publisher which provides objects to save. Must not be null.- Returns:
- the inserted objects.
-
doInsertAll
-
doInsertBatch
protected <T> Flux<T> doInsertBatch(String collectionName, Collection<? extends T> batchToSave, MongoWriter<Object> writer) -
save
Description copied from interface:ReactiveMongoOperationsSave the object to the collection for the entity type of the object to save. This will perform an insert if the object is not already present, that is an 'upsert'.
The object is converted to the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See Spring's Type Conversion for more details.A potential
Versionthe property will be auto incremented. The operation raises an error in case the document has been modified in between.- Specified by:
savein interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collection. Must not be null.- Returns:
- the saved object.
-
save
Description copied from interface:ReactiveMongoOperationsSave the object to the specified collection. This will perform an insert if the object is not already present, that is an 'upsert'.
The object is converted to the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See Spring's Type Conversion for more details.A potential
Versionthe property will be auto incremented. The operation raises an error in case the document has been modified in between.- Specified by:
savein interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collReactiveMongoOperationsection. Must not be null.collectionName- name of the collection to store the object in. Must not be null.- Returns:
- the saved object.
-
save
Description copied from interface:ReactiveMongoOperationsSave the object to the collection for the entity type of the object to save. This will perform an insert if the object is not already present, that is an 'upsert'.
The object is converted to the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See Spring's Type Conversion" for more details.A potential
Versionthe property will be auto incremented. The operation raises an error in case the document has been modified in between.The
objectToSavemust not be collection-like.- Specified by:
savein interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collection. Must not be null.- Returns:
- the saved object.
-
save
Description copied from interface:ReactiveMongoOperationsSave the object to the specified collection. This will perform an insert if the object is not already present, that is an 'upsert'.
The object is converted to the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See Spring's Type Conversion for more details.A potential
Versionthe property will be auto incremented. The operation raises an error in case the document has been modified in between.- Specified by:
savein interfaceReactiveMongoOperations- Parameters:
objectToSave- the object to store in the collection. Must not be null.collectionName- name of the collection to store the object in. Must not be null.- Returns:
- the saved object.
-
doSave
-
insertDocument
-
insertDocumentList
-
saveDocument
-
upsert
public Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition update, Class<?> entityClass) Description copied from interface:ReactiveMongoOperationsPerforms an upsert. If no document is found that matches the query, a new document is created and inserted by combining the query document and the update document.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.NOTE:
sortingis not supported bydb.collection.updateOne. UseReactiveMongoOperations.findAndModify(Query, UpdateDefinition, Class)instead.- Specified by:
upsertin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be upserted. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing object. Must not be null.entityClass- class that determines the collection to use. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
upsert
public Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition update, String collectionName) Description copied from interface:ReactiveMongoOperationsPerforms an upsert. If no document is found that matches the query, a new document is created and inserted by combining the query document and the update document.
NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of domain type information. UseReactiveMongoOperations.upsert(Query, UpdateDefinition, Class, String)to get full type specific support.- Specified by:
upsertin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be upserted. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing object. Must not be null.collectionName- name of the collection to update the object in.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
upsert
public Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Description copied from interface:ReactiveMongoOperationsPerforms an upsert. If no document is found that matches the query, a new document is created and inserted by combining the query document and the update document.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
upsertin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be upserted. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing object. Must not be null.entityClass- class of the pojo to be operated on. Must not be null.collectionName- name of the collection to update the object in. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
updateFirst
public Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, Class<?> entityClass) Description copied from interface:ReactiveMongoOperationsUpdates the first object that is found in the collection of the entity class that matches the query document with the provided update document.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
updateFirstin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be updated. TheQuerymay define asort orderto influence which document to update when potentially matching multiple candidates. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing. Must not be null.entityClass- class that determines the collection to use.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
updateFirst
public Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, String collectionName) Description copied from interface:ReactiveMongoOperationsUpdates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.
NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of domain type information. UseReactiveMongoOperations.updateFirst(Query, UpdateDefinition, Class, String)to get full type specific support.- Specified by:
updateFirstin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be updated. TheQuerymay define asort orderto influence which document to update when potentially matching multiple candidates. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing. Must not be null.collectionName- name of the collection to update the object in. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
updateFirst
public Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Description copied from interface:ReactiveMongoOperationsUpdates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
updateFirstin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be updated. TheQuerymay define asort orderto influence which document to update when potentially matching multiple candidates. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing. Must not be null.entityClass- class of the pojo to be operated on. Must not be null.collectionName- name of the collection to update the object in. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
updateMulti
public Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, Class<?> entityClass) Description copied from interface:ReactiveMongoOperationsUpdates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
updateMultiin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be updated. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing. Must not be null.entityClass- class of the pojo to be operated on. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
updateMulti
public Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, String collectionName) Description copied from interface:ReactiveMongoOperationsUpdates all objects that are found in the specified collection that matches the query document criteria with the provided updated document.
NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of domain type information. UseReactiveMongoOperations.updateMulti(Query, UpdateDefinition, Class, String)to get full type specific support.- Specified by:
updateMultiin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be updated. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing. Must not be null.collectionName- name of the collection to update the object in. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
updateMulti
public Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Description copied from interface:ReactiveMongoOperationsUpdates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.A potential
Versionproperty of the entityClass will be auto-incremented if not explicitly specified in the update.- Specified by:
updateMultiin interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to select a document to be updated. Must not be null.update- theUpdateDefinitionthat contains the updated object or$operators to manipulate the existing. Must not be null.entityClass- class of the pojo to be operated on. Must not be null.collectionName- name of the collection to update the object in. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous write. - See Also:
-
doUpdate
-
remove
Description copied from interface:ReactiveMongoOperationsRemove the given object from the collection by id and (if applicable) itsVersion.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
objectToRemove- must not be null.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
remove
public Mono<com.mongodb.client.result.DeleteResult> remove(Mono<? extends Object> objectToRemove, String collectionName) Description copied from interface:ReactiveMongoOperationsRemoves the given object from the given collection by id and (if applicable) itsVersion.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
objectToRemove- must not be null.collectionName- name of the collection where the documents will be removed from, must not be null or empty.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
remove
Description copied from interface:ReactiveMongoOperationsRemove the given object from the collection by id and (if applicable) itsVersion.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
object- must not be null.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
remove
Description copied from interface:ReactiveMongoOperationsRemoves the given object from the given collection.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
object- must not be null.collectionName- name of the collection where the documents will be removed from, must not be null or empty.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
remove
Description copied from interface:ReactiveMongoOperationsRemove all documents from the specified collection that match the provided query document criteria. There is no conversion/mapping done for any criteria using the id field.
NOTE: Any additional support for field mapping is not available due to the lack of domain type information. UseReactiveMongoOperations.remove(Query, Class, String)to get full type specific support.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to remove a document.collectionName- name of the collection where the documents will be removed from, must not be null or empty.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
remove
Description copied from interface:ReactiveMongoOperationsRemove all documents that match the provided query document criteria from the collection used to store the entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to remove a document.entityClass- class that determines the collection to use.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
remove
public Mono<com.mongodb.client.result.DeleteResult> remove(Query query, @Nullable Class<?> entityClass, String collectionName) Description copied from interface:ReactiveMongoOperationsRemove all documents that match the provided query document criteria from the collection used to store the entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.- Specified by:
removein interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to remove a document.entityClass- class of the pojo to be operated on. Can be null.collectionName- name of the collection where the documents will be removed from, must not be null or empty.- Returns:
- the
DeleteResultwhich lets you access the results of the previous delete.
-
doRemove
-
findAll
Description copied from interface:ReactiveMongoOperationsQuery for aFluxof objects of type T from the collection used by the entity class.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way to map objects since the test for class type is done in the client and not on the server.- Specified by:
findAllin interfaceReactiveMongoOperations- Parameters:
entityClass- the parametrized type of the returnedFlux.- Returns:
- the converted collection.
-
findAll
Description copied from interface:ReactiveMongoOperationsQuery for aFluxof objects of type T from the specified collection.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way to map objects since the test for class type is done in the client and not on the server.- Specified by:
findAllin interfaceReactiveMongoOperations- Parameters:
entityClass- the parametrized type of the returnedFlux.collectionName- name of the collection to retrieve the objects from.- Returns:
- the converted collection.
-
findAllAndRemove
Description copied from interface:ReactiveMongoOperationsReturns and removes all documents form the specified collection that match the provided query.
NOTE: Any additional support for field mapping is not available due to the lack of domain type information. UseReactiveMongoOperations.findAllAndRemove(Query, Class, String)to get full type specific support.- Specified by:
findAllAndRemovein interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to find and remove documents.collectionName- name of the collection where the documents will be removed from, must not be null or empty.- Returns:
- the
Fluxconverted objects deleted by this operation.
-
findAllAndRemove
Description copied from interface:ReactiveMongoOperationsReturns and removes all documents matching the given query form the collection used to store the entityClass.- Specified by:
findAllAndRemovein interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to find and remove documents.entityClass- class of the pojo to be operated on.- Returns:
- the
Fluxconverted objects deleted by this operation.
-
findAllAndRemove
Description copied from interface:ReactiveMongoOperationsReturns and removes all documents that match the provided query document criteria from the collection used to store the entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.- Specified by:
findAllAndRemovein interfaceReactiveMongoOperations- Parameters:
query- the query document that specifies the criteria used to find and remove documents.entityClass- class of the pojo to be operated on.collectionName- name of the collection where the documents will be removed from, must not be null or empty.- Returns:
- the
Fluxconverted objects deleted by this operation.
-
replace
public <T> Mono<com.mongodb.client.result.UpdateResult> replace(Query query, T replacement, ReplaceOptions options, String collectionName) Description copied from interface:ReactiveMongoOperationsReplace a single document matching theCriteriaof givenQuerywith thereplacementdocument takingReplaceOptionsinto account.- Specified by:
replacein interfaceReactiveMongoOperations- Parameters:
query- theQueryclass that specifies theCriteriaused to find a document. The query may * contain an indexhintor thecollationto use. TheQuerymay define asort orderto influence which document to replace when potentially matching multiple candidates. Must not be null.replacement- the replacement document. Must not be null.options- theReplaceOptionsholding additional information. Must not be null.- Returns:
- the
UpdateResultwhich lets you access the results of the previous replacement.
-
replace
protected <S,T> Mono<com.mongodb.client.result.UpdateResult> replace(Query query, Class<S> entityType, T replacement, ReplaceOptions options, String collectionName) -
tail
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified type. The stream uses atailablecursor that may be an infinite stream. The stream will not be completed unless theSubscriptioniscanceled.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
tailin interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass- the parametrized type of the returnedFlux.- Returns:
- the
Fluxof converted objects.
-
tail
Description copied from interface:ReactiveMongoOperationsMap the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified type. The stream uses atailablecursor that may be an infinite stream. The stream will not be completed unless theSubscriptioniscanceled.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverterwill be used.
The query is specified as aQuerywhich can be created either using theBasicQueryor the more feature richQuery.- Specified by:
tailin interfaceReactiveMongoOperations- Parameters:
query- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass- the parametrized type of the returnedFlux.collectionName- name of the collection to retrieve the objects from.- Returns:
- the
Fluxof converted objects.
-
changeStream
public <T> Flux<ChangeStreamEvent<T>> changeStream(@Nullable String database, @Nullable String collectionName, ChangeStreamOptions options, Class<T> targetType) Description copied from interface:ReactiveMongoOperationsSubscribe to a MongoDB Change Stream via the reactive infrastructure. Use the optional providedAggregationto filter events. The stream will not be completed unless theSubscriptioniscanceled.
TheChangeStreamEvent.getBody()is mapped to the resultType while theChangeStreamEvent.getRaw()contains the unmodified payload.
UseChangeStreamOptionsto set arguments likethe resumseTokenfor resuming change streams.- Specified by:
changeStreamin interfaceReactiveMongoOperations- Parameters:
database- the database to watch. Can be null, uses configured default if so.collectionName- the collection to watch. Can be null, watches all collections if so.options- must not be null. UseChangeStreamOptions.empty().targetType- the result type to use.- Returns:
- the
Fluxemittingeventsas they arrive. - See Also:
-
mapReduce
public <T> Flux<T> mapReduce(Query filterQuery, Class<?> domainType, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Description copied from interface:ReactiveMongoOperationsExecute a map-reduce operation. UseMapReduceOptionsto optionally specify an output collection and other args.- Specified by:
mapReducein interfaceReactiveMongoOperations- Parameters:
filterQuery- the selection criteria for the documents going input to the map function. Must not be null.domainType- source type used to determine the input collection name and map the filterQueryagainst. Must not be null.resultType- the mapping target of the operations result documents. Must not be null.mapFunction- the JavaScript map function. Must not be null.reduceFunction- the JavaScript reduce function. Must not be null.options- additional options like output collection. Must not be null.- Returns:
- a
Fluxemitting the result document sequence. Never null.
-
mapReduce
public <T> Flux<T> mapReduce(Query filterQuery, Class<?> domainType, String inputCollectionName, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Description copied from interface:ReactiveMongoOperationsExecute a map-reduce operation. UseMapReduceOptionsto optionally specify an output collection and other args.- Specified by:
mapReducein interfaceReactiveMongoOperations- Parameters:
filterQuery- the selection criteria for the documents going input to the map function. Must not be null.domainType- source type used to map the filterQueryagainst. Must not be null.inputCollectionName- the input collection.resultType- the mapping target of the operations result documents. Must not be null.mapFunction- the JavaScript map function. Must not be null.reduceFunction- the JavaScript reduce function. Must not be null.options- additional options like output collection. Must not be null.- Returns:
- a
Fluxemitting the result document sequence. Never null.
-
query
Description copied from interface:ReactiveFindOperationStart creating a find operation for the given domainType.- Specified by:
queryin interfaceReactiveFindOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
ReactiveFindOperation.ReactiveFind. Never null.
-
update
Description copied from interface:ReactiveUpdateOperationStart creating an update operation for the given domainType.- Specified by:
updatein interfaceReactiveUpdateOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
ReactiveUpdateOperation.ReactiveUpdate. Never null.
-
remove
Description copied from interface:ReactiveRemoveOperationStart creating a remove operation for the given domainType.- Specified by:
removein interfaceReactiveRemoveOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
ReactiveRemoveOperation.ReactiveRemove. Never null.
-
insert
Description copied from interface:ReactiveInsertOperationStart creating an insert operation for given domainType.- Specified by:
insertin interfaceReactiveInsertOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
ReactiveInsertOperation.ReactiveInsert. Never null.
-
aggregateAndReturn
public <T> ReactiveAggregationOperation.ReactiveAggregation<T> aggregateAndReturn(Class<T> domainType) Description copied from interface:ReactiveAggregationOperationStart creating an aggregation operation that returns results mapped to the given domain type.
UseTypedAggregationto specify a potentially different input type for he aggregation.- Specified by:
aggregateAndReturnin interfaceReactiveAggregationOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
ReactiveAggregationOperation.ReactiveAggregation. Never null.
-
mapReduce
Description copied from interface:ReactiveMapReduceOperationStart creating a mapReduce operation for the given domainType.- Specified by:
mapReducein interfaceReactiveMapReduceOperation- Parameters:
domainType- must not be null.- Returns:
- new instance of
ExecutableFindOperation.ExecutableFind.
-
changeStream
Description copied from interface:ReactiveChangeStreamOperationStart creating a change stream operation for the given domainType watching all collections within the database.
Consider limiting events be defining acollectionand/orfilter.- Specified by:
changeStreamin interfaceReactiveChangeStreamOperation- Parameters:
domainType- must not be null. UseDocumentto obtain raw elements.- Returns:
- new instance of
ReactiveChangeStreamOperation.ReactiveChangeStream. Never null.
-
doFindAndDelete
Retrieve and remove all documents matching the givenqueryby callingfind(Query, Class, String)andremove(Query, Class, String), whereas theQueryforremove(Query, Class, String)is constructed out of the find result.- Parameters:
collectionName-query-entityClass-- Returns:
-
doCreateCollection
protected Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> doCreateCollection(String collectionName, com.mongodb.client.model.CreateCollectionOptions collectionOptions) Create the specified collection using the provided options- Parameters:
collectionName-collectionOptions-- Returns:
- the collection that was created
-
doFindOne
protected <T> Mono<T> doFindOne(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, @Nullable org.bson.Document fields, Class<T> entityClass, @Nullable Collation collation) Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter. The query document is specified as a standardDocumentand so is the fields specification.- Parameters:
collectionName- name of the collection to retrieve the objects from.collectionPreparer- the preparer to prepare the collection for the actual use.query- the query document that specifies the criteria used to find a record.fields- the document that specifies the fields to be returned.entityClass- the parameterized type of the returned list.collation- can be null.- Returns:
- the
Listof converted objects.
-
doFindOne
protected <T> Mono<T> doFindOne(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, @Nullable org.bson.Document fields, Class<T> entityClass, FindPublisherPreparer preparer) Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter. The query document is specified as a standardDocumentand so is the fields specification.- Parameters:
collectionName- name of the collection to retrieve the objects from.collectionPreparer- the preparer to prepare the collection for the actual use.query- the query document that specifies the criteria used to find a record.fields- the document that specifies the fields to be returned.entityClass- the parameterized type of the returned list.preparer- the preparer modifying collection and publisher to fit the needs.- Returns:
- the
Listof converted objects. - Since:
- 2.2
-
doFind
protected <T> Flux<T> doFind(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<T> entityClass) Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter. The query document is specified as a standard Document and so is the fields specification.- Parameters:
collectionName- name of the collection to retrieve the objects fromcollectionPreparer- the preparer to prepare the collection for the actual use.query- the query document that specifies the criteria used to find a recordfields- the document that specifies the fields to be returnedentityClass- the parameterized type of the returned list.- Returns:
- the List of converted objects.
-
doFind
protected <T> Flux<T> doFind(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<T> entityClass, FindPublisherPreparer preparer) Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. The object is converted from the MongoDB native representation using an instance of . The query document is specified as a standard Document and so is the fields specification.- Parameters:
collectionName- name of the collection to retrieve the objects from.collectionPreparer- the preparer to prepare the collection for the actual use.query- the query document that specifies the criteria used to find a record.fields- the document that specifies the fields to be returned.entityClass- the parameterized type of the returned list.preparer- allows for customization of theFindIterableused when iterating over the result set, (apply limits, skips and so on).- Returns:
- the
Listof converted objects.
-
doFind
protected <S,T> Flux<T> doFind(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, Class<S> entityClass, @Nullable FindPublisherPreparer preparer, org.springframework.data.mongodb.core.ReactiveMongoTemplate.DocumentCallback<T> objectCallback) -
convertToCreateCollectionOptions
protected com.mongodb.client.model.CreateCollectionOptions convertToCreateCollectionOptions(@Nullable CollectionOptions collectionOptions) -
convertToCreateCollectionOptions
protected com.mongodb.client.model.CreateCollectionOptions convertToCreateCollectionOptions(@Nullable CollectionOptions collectionOptions, Class<?> entityType) -
doFindAndRemove
protected <T> Mono<T> doFindAndRemove(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, org.bson.Document sort, @Nullable Collation collation, Class<T> entityClass) Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter. The first document that matches the query is returned and also removed from the collection in the database.
The query document is specified as a standard Document and so is the fields specification.- Parameters:
collectionName- name of the collection to retrieve the objects from.collectionPreparer- the preparer to prepare the collection for the actual use.query- the query document that specifies the criteria used to find a record.collation- collation.entityClass- the parameterized type of the returned list.- Returns:
- the List of converted objects.
-
doFindAndModify
protected <T> Mono<T> doFindAndModify(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document query, org.bson.Document fields, org.bson.Document sort, Class<T> entityClass, UpdateDefinition update, FindAndModifyOptions options) -
doFindAndReplace
protected <T> Mono<T> doFindAndReplace(String collectionName, CollectionPreparer<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> collectionPreparer, org.bson.Document mappedQuery, org.bson.Document mappedFields, org.bson.Document mappedSort, com.mongodb.client.model.Collation collation, Class<?> entityType, org.bson.Document replacement, FindAndReplaceOptions options, Class<T> resultType) Customize this part for findAndReplace.- Parameters:
collectionName- The name of the collection to perform the operation in.collectionPreparer- the preparer to prepare the collection for the actual use.mappedQuery- the query to look up documents.mappedFields- the fields to project the result to.mappedSort- the sort to be applied when executing the query.collation- collation settings for the query. Can be null.entityType- the source domain type.replacement- the replacementDocument.options- applicable options.resultType- the target domain type.- Returns:
Mono.empty()if object does not exist,return newis false andupsertis false.- Since:
- 2.1
-
maybeEmitEvent
-
maybeCallBeforeConvert
-
maybeCallBeforeSave
-
maybeCallAfterSave
-
maybeCallAfterConvert
-
ensureNotCollectionLike
- Parameters:
source- can be null.- Since:
- 3.2.
-
prepareCollection
protected com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> prepareCollection(com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> collection) Prepare the collection before any processing is done using it. This allows a convenient way to apply settings like withCodecRegistry() etc. Can be overridden in sub-classes.- Parameters:
collection-
-
prepareDatabase
protected com.mongodb.reactivestreams.client.MongoDatabase prepareDatabase(com.mongodb.reactivestreams.client.MongoDatabase database) - Parameters:
database-- Returns:
- Since:
- 2.1
-
prepareWriteConcern
Prepare the WriteConcern before any processing is done using it. This allows a convenient way to apply custom settings in sub-classes.
The returnedWriteConcernwill be defaulted toWriteConcern.ACKNOWLEDGEDwhenWriteResultCheckingis set toWriteResultChecking.EXCEPTION.- Parameters:
mongoAction- any WriteConcern already configured or null.- Returns:
- The prepared WriteConcern or null.
- See Also:
-
getMongoDatabaseFactory
- Returns:
- the
MongoDatabaseFactoryin use. - Since:
- 3.1.4
-