Class ReactiveMongoTemplate

java.lang.Object
org.springframework.data.mongodb.core.ReactiveMongoTemplate
All Implemented Interfaces:
Aware, ApplicationContextAware, ReactiveAggregationOperation, ReactiveChangeStreamOperation, ReactiveFindOperation, ReactiveFluentMongoOperations, ReactiveInsertOperation, ReactiveMapReduceOperation, ReactiveMongoOperations, ReactiveRemoveOperation, ReactiveUpdateOperation

public class ReactiveMongoTemplate extends Object implements ReactiveMongoOperations, ApplicationContextAware
Primary implementation of 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.

Since:
2.0
Author:
Mark Paluch, Christoph Strobl, Roman Puchkovskiy, Mathieu Ouellet, Yadhukrishna S Pai
  • Field Details

    • NO_OP_REF_RESOLVER

      public static final DbRefResolver NO_OP_REF_RESOLVER
  • Constructor Details

    • ReactiveMongoTemplate

      public ReactiveMongoTemplate(com.mongodb.reactivestreams.client.MongoClient mongoClient, String databaseName)
      Constructor used for a basic template configuration.
      Parameters:
      mongoClient - must not be null.
      databaseName - must not be null or empty.
    • ReactiveMongoTemplate

      public ReactiveMongoTemplate(ReactiveMongoDatabaseFactory mongoDatabaseFactory)
      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 by Flux.doOnError(Consumer) on reactive type materialization via Publisher.subscribe(Subscriber). This callback is used during non-blocking subscription of e.g. index creation Publishers. Must not be null.
      Since:
      2.1
  • Method Details

    • setWriteResultChecking

      public void setWriteResultChecking(@Nullable WriteResultChecking resultChecking)
      Configures the WriteResultChecking to be used with the template. Setting null will reset the default of DEFAULT_WRITE_RESULT_CHECKING.
      Parameters:
      resultChecking -
    • setWriteConcern

      public void setWriteConcern(@Nullable com.mongodb.WriteConcern writeConcern)
      Configures the WriteConcern to be used with the template. If none is configured the WriteConcern configured on the MongoDatabaseFactory will apply.
      Parameters:
      writeConcern - can be null.
    • setWriteConcernResolver

      public void setWriteConcernResolver(@Nullable WriteConcernResolver writeConcernResolver)
      Configures the WriteConcernResolver to 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 the ReadPreference before any operations are performed.
      Parameters:
      readPreference -
    • setEntityLifecycleEventsEnabled

      public void setEntityLifecycleEventsEnabled(boolean enabled)
      Configure whether lifecycle events such as AfterLoadEvent, BeforeSaveEvent, etc. should be published or whether emission should be suppressed. Enabled by default.
      Parameters:
      enabled - true to enable entity lifecycle events; false to disable entity lifecycle events.
      Since:
      4.0
      See Also:
    • setApplicationContext

      public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
      Specified by:
      setApplicationContext in interface ApplicationContextAware
      Throws:
      BeansException
    • setEntityCallbacks

      public void setEntityCallbacks(ReactiveEntityCallbacks entityCallbacks)
      Set the ReactiveEntityCallbacks instance to use when invoking callbacks like the ReactiveBeforeSaveCallback.
      Overrides potentially existing ReactiveEntityCallbacks.
      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 - use MongoCollection.estimatedDocumentCount() for unpaged and empty queries if true.
      Since:
      3.4
    • getConverter

      public MongoConverter getConverter()
      Returns the default MongoConverter.
      Specified by:
      getConverter in interface ReactiveMongoOperations
      Returns:
    • indexOps

      public ReactiveIndexOperations indexOps(String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns the reactive operations that can be performed on indexes
      Specified by:
      indexOps in interface ReactiveMongoOperations
      Parameters:
      collectionName - must not be null.
      Returns:
      index operations on the named collection
    • indexOps

      public ReactiveIndexOperations indexOps(Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Returns the reactive operations that can be performed on indexes
      Specified by:
      indexOps in interface ReactiveMongoOperations
      Parameters:
      entityClass - must not be null.
      Returns:
      index operations on the named collection associated with the given entity class
    • getCollectionName

      public String getCollectionName(Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      The collection name used for the specified class by this template.
      Specified by:
      getCollectionName in interface ReactiveMongoOperations
      Parameters:
      entityClass - must not be null.
      Returns:
      never null.
    • executeCommand

      public reactor.core.publisher.Mono<org.bson.Document> executeCommand(String jsonCommand)
      Description copied from interface: ReactiveMongoOperations
      Execute 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:
      executeCommand in interface ReactiveMongoOperations
      Parameters:
      jsonCommand - a MongoDB command expressed as a JSON string.
      Returns:
      a result object returned by the action
    • executeCommand

      public reactor.core.publisher.Mono<org.bson.Document> executeCommand(org.bson.Document command)
      Description copied from interface: ReactiveMongoOperations
      Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.
      Specified by:
      executeCommand in interface ReactiveMongoOperations
      Parameters:
      command - a MongoDB command.
      Returns:
      a result object returned by the action
    • executeCommand

      public reactor.core.publisher.Mono<org.bson.Document> executeCommand(org.bson.Document command, @Nullable com.mongodb.ReadPreference readPreference)
      Description copied from interface: ReactiveMongoOperations
      Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's data access exception hierarchy.
      Specified by:
      executeCommand in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Flux<T> execute(Class<?> entityClass, ReactiveCollectionCallback<T> action)
      Description copied from interface: ReactiveMongoOperations
      Executes the given ReactiveCollectionCallback on 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:
      execute in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Flux<T> execute(ReactiveDatabaseCallback<T> action)
      Description copied from interface: ReactiveMongoOperations
      Executes a ReactiveDatabaseCallback translating any exceptions as necessary.
      Allows for returning a result object, that is a domain object or a collection of domain objects.
      Specified by:
      execute in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Flux<T> execute(String collectionName, ReactiveCollectionCallback<T> callback)
      Description copied from interface: ReactiveMongoOperations
      Executes the given ReactiveCollectionCallback on 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:
      execute in interface ReactiveMongoOperations
      Type Parameters:
      T - return type.
      Parameters:
      collectionName - the name of the collection that specifies which MongoCollection instance 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(org.reactivestreams.Publisher<com.mongodb.reactivestreams.client.ClientSession> sessionProvider)
      Description copied from interface: ReactiveMongoOperations
      Obtain a session bound instance of ReactiveSessionScoped binding the ClientSession provided by the given Publisher to each and every command issued against MongoDB.
      Note: It is up to the caller to manage the ClientSession lifecycle. Use ReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer) to provide a hook for processing the ClientSession when done.
      Specified by:
      withSession in interface ReactiveMongoOperations
      Parameters:
      sessionProvider - must not be null.
      Returns:
      new instance of ReactiveSessionScoped. Never null.
    • setSessionSynchronization

      public void setSessionSynchronization(SessionSynchronization sessionSynchronization)
      Define if ReactiveMongoTemplate should participate in transactions. Default is set to SessionSynchronization.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: ReactiveMongoOperations
      Obtain a ClientSession bound instance of ReactiveMongoOperations.
      Note: It is up to the caller to manage the ClientSession lifecycle.
      Specified by:
      withSession in interface ReactiveMongoOperations
      Returns:
      ClientSession bound instance of ReactiveMongoOperations.
    • withSession

      public ReactiveSessionScoped withSession(com.mongodb.ClientSessionOptions sessionOptions)
      Description copied from interface: ReactiveMongoOperations
      Obtain a session bound instance of SessionScoped binding a new ClientSession with given sessionOptions to each and every command issued against MongoDB.
      Note: It is up to the caller to manage the ClientSession lifecycle. Use ReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer) to provide a hook for processing the ClientSession when done.
      Specified by:
      withSession in interface ReactiveMongoOperations
      Parameters:
      sessionOptions - must not be null.
      Returns:
      new instance of ReactiveSessionScoped. Never null.
    • createFlux

      public <T> reactor.core.publisher.Flux<T> createFlux(ReactiveDatabaseCallback<T> callback)
      Create a reusable Flux for a ReactiveDatabaseCallback. It's up to the developer to choose to obtain a new Flux or to reuse the Flux.
      Parameters:
      callback - must not be null
      Returns:
      a Flux wrapping the ReactiveDatabaseCallback.
    • createMono

      public <T> reactor.core.publisher.Mono<T> createMono(ReactiveDatabaseCallback<T> callback)
      Create a reusable Mono for a ReactiveDatabaseCallback. It's up to the developer to choose to obtain a new Flux or to reuse the Flux.
      Parameters:
      callback - must not be null
      Returns:
      a Mono wrapping the ReactiveDatabaseCallback.
    • createFlux

      public <T> reactor.core.publisher.Flux<T> createFlux(String collectionName, ReactiveCollectionCallback<T> callback)
      Create a reusable Flux for the collectionName and ReactiveCollectionCallback.
      Parameters:
      collectionName - must not be empty or null.
      callback - must not be null.
      Returns:
      a reusable Flux wrapping the ReactiveCollectionCallback.
    • createMono

      public <T> reactor.core.publisher.Mono<T> createMono(String collectionName, ReactiveCollectionCallback<T> callback)
      Create a reusable Mono for the collectionName and ReactiveCollectionCallback.
      Type Parameters:
      T -
      Parameters:
      collectionName - must not be empty or null.
      callback - must not be null.
      Returns:
      a reusable Mono wrapping the ReactiveCollectionCallback.
    • createCollection

      public <T> reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Create an uncapped collection with a name based on the provided entity class.
      Specified by:
      createCollection in interface ReactiveMongoOperations
      Parameters:
      entityClass - class that determines the collection to create.
      Returns:
      the created collection.
    • createCollection

      public <T> reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(Class<T> entityClass, @Nullable CollectionOptions collectionOptions)
      Description copied from interface: ReactiveMongoOperations
      Create a collection with a name based on the provided entity class using the options.
      Specified by:
      createCollection in interface ReactiveMongoOperations
      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 reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Create an uncapped collection with the provided name.
      Specified by:
      createCollection in interface ReactiveMongoOperations
      Parameters:
      collectionName - name of the collection.
      Returns:
      the created collection.
    • createCollection

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(String collectionName, @Nullable CollectionOptions collectionOptions)
      Description copied from interface: ReactiveMongoOperations
      Create a collection with the provided name and options.
      Specified by:
      createCollection in interface ReactiveMongoOperations
      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 reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, Class<?> source, AggregationPipeline pipeline, @Nullable ViewOptions options)
      Description copied from interface: ReactiveMongoOperations
      Create a view with the provided name. The view content is defined by the pipeline on another collection or view identified by the given source type.
      Specified by:
      createView in interface ReactiveMongoOperations
      Parameters:
      name - the name of the view to create.
      source - the type defining the views source collection.
      pipeline - the AggregationPipeline defining the view content.
      options - additional settings to apply when creating the view. Can be null.
    • createView

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, String source, AggregationPipeline pipeline, @Nullable ViewOptions options)
      Description copied from interface: ReactiveMongoOperations
      Create a view with the provided name. The view content is defined by the pipeline on another collection or view identified by the given source.
      Specified by:
      createView in interface ReactiveMongoOperations
      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 - the AggregationPipeline defining the view content.
      options - additional settings to apply when creating the view. Can be null.
    • doCreateView

      protected reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> doCreateView(String name, String source, List<org.bson.Document> pipeline, @Nullable ViewOptions options)
    • getCollection

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> getCollection(String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Get a MongoCollection by 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 via ReactiveMongoOperations.createCollection(Class). Please make sure to check if the collection exists first.
      Translate any exceptions as necessary.
      Specified by:
      getCollection in interface ReactiveMongoOperations
      Parameters:
      collectionName - name of the collection.
      Returns:
      an existing collection or one created on first server interaction.
    • collectionExists

      public <T> reactor.core.publisher.Mono<Boolean> collectionExists(Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Check to see if a collection with a name indicated by the entity class exists.
      Translate any exceptions as necessary.
      Specified by:
      collectionExists in interface ReactiveMongoOperations
      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

      public reactor.core.publisher.Mono<Boolean> collectionExists(String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Check to see if a collection with a given name exists.
      Translate any exceptions as necessary.
      Specified by:
      collectionExists in interface ReactiveMongoOperations
      Parameters:
      collectionName - name of the collection. Must not be null.
      Returns:
      true if a collection with the given name is found, false otherwise.
    • dropCollection

      public <T> reactor.core.publisher.Mono<Void> dropCollection(Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Drop the collection with the name indicated by the entity class.
      Translate any exceptions as necessary.
      Specified by:
      dropCollection in interface ReactiveMongoOperations
      Parameters:
      entityClass - class that determines the collection to drop/delete. Must not be null.
    • dropCollection

      public reactor.core.publisher.Mono<Void> dropCollection(String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Drop the collection with the given name.
      Translate any exceptions as necessary.
      Specified by:
      dropCollection in interface ReactiveMongoOperations
      Parameters:
      collectionName - name of the collection to drop/delete.
    • bulkOps

      public ReactiveBulkOperations bulkOps(BulkOperations.BulkMode mode, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns a new ReactiveBulkOperations for 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. Use ReactiveMongoOperations.bulkOps(BulkMode, Class, String) to get full type specific support.
      Specified by:
      bulkOps in interface ReactiveMongoOperations
      Parameters:
      mode - the BulkOperations.BulkMode to use for bulk operations, must not be null.
      collectionName - the name of the collection to work on, must not be null or empty.
      Returns:
      ReactiveBulkOperations on the named collection
    • bulkOps

      public ReactiveBulkOperations bulkOps(BulkOperations.BulkMode mode, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Returns a new ReactiveBulkOperations for the given entity type.
      Specified by:
      bulkOps in interface ReactiveMongoOperations
      Parameters:
      mode - the BulkOperations.BulkMode to use for bulk operations, must not be null.
      entityClass - the name of the entity class, must not be null.
      Returns:
      ReactiveBulkOperations on 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: ReactiveMongoOperations
      Returns a new ReactiveBulkOperations for the given entity type and collection name.
      Specified by:
      bulkOps in interface ReactiveMongoOperations
      Parameters:
      mode - the BulkOperations.BulkMode to 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:
      ReactiveBulkOperations on the named collection associated with the given entity class.
    • getCollectionNames

      public reactor.core.publisher.Flux<String> getCollectionNames()
      Description copied from interface: ReactiveMongoOperations
      A set of collection names.
      Specified by:
      getCollectionNames in interface ReactiveMongoOperations
      Returns:
      Flux of collection names.
    • getMongoDatabase

      public reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> getMongoDatabase()
    • doGetDatabase

      protected reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoDatabase> doGetDatabase()
    • findOne

      public <T> reactor.core.publisher.Mono<T> findOne(Query query, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      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.
      The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      findOne in interface ReactiveMongoOperations
      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 returned Mono.
      Returns:
      the converted object.
    • findOne

      public <T> reactor.core.publisher.Mono<T> findOne(Query query, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Map 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 of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      findOne in interface ReactiveMongoOperations
      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 returned Mono.
      collectionName - name of the collection to retrieve the objects from.
      Returns:
      the converted object.
    • exists

      public reactor.core.publisher.Mono<Boolean> exists(Query query, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Determine result of given Query contains at least one element.
      Specified by:
      exists in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the criteria used to find a document.
      entityClass - the parametrized type.
      Returns:
      true if the query yields a result.
    • exists

      public reactor.core.publisher.Mono<Boolean> exists(Query query, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Determine result of given Query contains at least one element.
      NOTE: Any additional support for query/field mapping, etc. is not available due to the lack of domain type information. Use ReactiveMongoOperations.exists(Query, Class, String) to get full type specific support.
      Specified by:
      exists in interface ReactiveMongoOperations
      Parameters:
      query - the Query class 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

      public reactor.core.publisher.Mono<Boolean> exists(Query query, @Nullable Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Determine result of given Query contains at least one element.
      Specified by:
      exists in interface ReactiveMongoOperations
      Parameters:
      query - the Query class 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

      public <T> reactor.core.publisher.Flux<T> find(Query query, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Map the results of an ad-hoc query on the collection for the entity class to a Flux of the specified type.
      The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      find in interface ReactiveMongoOperations
      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 returned Flux. Must not be null.
      Returns:
      the Flux of converted objects.
    • find

      public <T> reactor.core.publisher.Flux<T> find(@Nullable Query query, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Map the results of an ad-hoc query on the specified collection to a Flux of the specified type.
      The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      find in interface ReactiveMongoOperations
      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 returned Flux.
      collectionName - name of the collection to retrieve the objects from. Must not be null.
      Returns:
      the Flux of converted objects.
    • scroll

      public <T> reactor.core.publisher.Mono<Window<T>> scroll(Query query, Class<T> entityType)
      Description copied from interface: ReactiveMongoOperations
      Query for a scroll of objects of type T from the specified collection.
      Make sure to either set Query.skip(long) or Query.with(KeysetScrollPosition) along with Query.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 of MappingMongoConverter will 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-nullable sort properties as MongoDB does not support criteria to reconstruct a query result from absent document fields or null values through $gt/$lt operators.

      Specified by:
      scroll in interface ReactiveMongoOperations
      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:
      Mono emitting the converted window.
      See Also:
    • scroll

      public <T> reactor.core.publisher.Mono<Window<T>> scroll(Query query, Class<T> entityType, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Query for a window of objects of type T from the specified collection.
      Make sure to either set Query.skip(long) or Query.with(KeysetScrollPosition) along with Query.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 of MappingMongoConverter will 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-nullable sort properties as MongoDB does not support criteria to reconstruct a query result from absent document fields or null values through $gt/$lt operators.

      Specified by:
      scroll in interface ReactiveMongoOperations
      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:
      Mono emitting the converted window.
      See Also:
    • findById

      public <T> reactor.core.publisher.Mono<T> findById(Object id, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Returns 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:
      findById in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Mono<T> findById(Object id, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns the document with the given id from the given collection mapped onto the given target class.
      Specified by:
      findById in interface ReactiveMongoOperations
      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> reactor.core.publisher.Flux<T> findDistinct(Query query, String field, Class<?> entityClass, Class<T> resultClass)
      Description copied from interface: ReactiveMongoOperations
      Finds the distinct values for a specified field across a single MongoCollection or view and returns the results in a Flux.
      Specified by:
      findDistinct in interface ReactiveMongoOperations
      Parameters:
      query - filter Query to 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 actual MongoCollection and mapping the Query to the domain type fields. Must not be null.
      resultClass - the result type. Must not be null.
      Returns:
      never null.
    • findDistinct

      public <T> reactor.core.publisher.Flux<T> findDistinct(Query query, String field, String collectionName, Class<?> entityClass, Class<T> resultClass)
      Description copied from interface: ReactiveMongoOperations
      Finds the distinct values for a specified field across a single MongoCollection or view and returns the results in a Flux.
      Specified by:
      findDistinct in interface ReactiveMongoOperations
      Parameters:
      query - filter Query to 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 actual MongoCollection. Must not be null.
      entityClass - the domain type used for mapping the Query to the domain type fields.
      resultClass - the result type. Must not be null.
      Returns:
      never null.
    • aggregate

      public <O> reactor.core.publisher.Flux<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType)
      Description copied from interface: ReactiveMongoOperations
      Execute an aggregation operation.

      The raw results will be mapped to the given entity class.

      Aggregation streaming cannot be used with aggregation explain nor with AggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size cause IllegalArgumentException.

      Specified by:
      aggregate in interface ReactiveMongoOperations
      Parameters:
      aggregation - The TypedAggregation specification 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 returned Flux. Must not be null.
      Returns:
      The results of the aggregation operation.
    • aggregate

      public <O> reactor.core.publisher.Flux<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType)
      Description copied from interface: ReactiveMongoOperations
      Execute 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 the aggregation input type.
      Aggregation streaming cannot be used with aggregation explain nor with AggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size cause IllegalArgumentException.
      Specified by:
      aggregate in interface ReactiveMongoOperations
      Parameters:
      aggregation - The TypedAggregation specification holding the aggregation operations. Must not be null.
      outputType - The parametrized type of the returned Flux. Must not be null.
      Returns:
      The results of the aggregation operation.
    • aggregate

      public <O> reactor.core.publisher.Flux<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType)
      Description copied from interface: ReactiveMongoOperations
      Execute an aggregation operation.
      The raw results will be mapped to the given ouputType. The name of the inputCollection is derived from the inputType.
      Aggregation streaming cannot be used with aggregation explain nor with AggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size cause IllegalArgumentException.
      Specified by:
      aggregate in interface ReactiveMongoOperations
      Parameters:
      aggregation - The Aggregation specification 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 returned Flux. Must not be null.
      Returns:
      The results of the aggregation operation.
    • aggregate

      public <O> reactor.core.publisher.Flux<O> aggregate(Aggregation aggregation, String collectionName, Class<O> outputType)
      Description copied from interface: ReactiveMongoOperations
      Execute an aggregation operation.
      The raw results will be mapped to the given entity class.
      Aggregation streaming cannot be used with aggregation explain nor with AggregationOptions.getCursorBatchSize(). Enabling explanation mode or setting batch size cause IllegalArgumentException.
      Specified by:
      aggregate in interface ReactiveMongoOperations
      Parameters:
      aggregation - The Aggregation specification 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 returned Flux. Must not be null.
      Returns:
      The results of the aggregation operation.
    • doAggregate

      protected <O> reactor.core.publisher.Flux<O> doAggregate(Aggregation aggregation, String collectionName, @Nullable Class<?> inputType, Class<O> outputType)
    • geoNear

      public <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Returns Flux of GeoResult for all entities matching the given NearQuery. 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 the NearQuery if you expect a particular number of results.

      MongoDB 4.2 has removed the geoNear command. This method uses since version 2.2 aggregations and the $geoNear aggregation command to emulate geoNear command 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:
      geoNear in interface ReactiveMongoOperations
      Parameters:
      near - must not be null.
      entityClass - must not be null.
      Returns:
      the converted GeoResults.
    • geoNear

      public <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns Flux of GeoResult for all entities matching the given NearQuery. Note, that MongoDB limits the number of results by default. Make sure to add an explicit limit to the NearQuery if you expect a particular number of results.

      MongoDB 4.2 has removed the geoNear command. This method uses since version 2.2 aggregations and the $geoNear aggregation command to emulate geoNear command 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:
      geoNear in interface ReactiveMongoOperations
      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

      protected <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near, Class<?> entityClass, String collectionName, Class<T> returnType)
    • findAndModify

      public <T> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Triggers findAndModify to apply provided Update on documents matching Criteria of given Query.

      A potential Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      findAndModify in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the Criteria used to find a document and also an optional fields specification. Must not be null.
      update - the UpdateDefinition to 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> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Triggers findAndModify to apply provided Update on documents matching Criteria of given Query.

      A potential Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      findAndModify in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the Criteria used to find a document and also an optional fields specification. Must not be null.
      update - the UpdateDefinition to 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> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Triggers findAndModify to apply provided Update on documents matching Criteria of given Query taking FindAndModifyOptions into account.

      A potential Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      findAndModify in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the Criteria used to find a document and also an optional fields specification.
      update - the UpdateDefinition to apply on matching documents.
      options - the FindAndModifyOptions holding 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> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Triggers findAndModify to apply provided Update on documents matching Criteria of given Query taking FindAndModifyOptions into account.

      A potential Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      findAndModify in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the Criteria used to find a document and also an optional fields specification. Must not be null.
      update - the UpdateDefinition to apply on matching documents. Must not be null.
      options - the FindAndModifyOptions holding 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> reactor.core.publisher.Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType, String collectionName, Class<T> resultType)
      Description copied from interface: ReactiveMongoOperations
      Triggers findOneAndReplace to replace a single document matching Criteria of given Query with the replacement document taking FindAndReplaceOptions into account.
      NOTE: The replacement entity must not hold an id.
      Specified by:
      findAndReplace in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the Criteria used to find a document and also an optional fields specification. Must not be null.
      replacement - the replacement document. Must not be null.
      options - the FindAndModifyOptions holding additional information. Must not be null.
      entityType - the type used for mapping the Query to 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 of Object.class instead.
      Returns:
      the converted object that was updated or Mono.empty(), if not found. Depending on the value of FindAndReplaceOptions.isReturnNew() this will either be the object as it was before the update or as it is after the update.
    • findAndRemove

      public <T> reactor.core.publisher.Mono<T> findAndRemove(Query query, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      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. 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 a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      findAndRemove in interface ReactiveMongoOperations
      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 returned Mono.
      Returns:
      the converted object
    • findAndRemove

      public <T> reactor.core.publisher.Mono<T> findAndRemove(Query query, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Map 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 of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      findAndRemove in interface ReactiveMongoOperations
      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 returned Mono.
      collectionName - name of the collection to retrieve the objects from.
      Returns:
      the converted object.
    • count

      public reactor.core.publisher.Mono<Long> count(Query query, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Returns the number of documents for the given Query by querying the collection of the given entity class.
      NOTE: Query offset and limit can 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 use ReactiveMongoOperations.estimatedCount(Class) for empty queries instead of running an aggregation execution which may have an impact on performance.
      Specified by:
      count in interface ReactiveMongoOperations
      Parameters:
      query - the Query class 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

      public reactor.core.publisher.Mono<Long> count(Query query, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns the number of documents for the given Query querying the given collection. The given Query must solely consist of document field references as we lack type information to map potential property references onto document fields. Use ReactiveMongoOperations.count(Query, Class, String) to get full type specific support.
      NOTE: Query offset and limit can 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 use ReactiveMongoOperations.estimatedCount(Class) for empty queries instead of running an aggregation execution which may have an impact on performance.
      Specified by:
      count in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the criteria used to find documents.
      collectionName - must not be null or empty.
      Returns:
      the count of matching documents.
      See Also:
    • count

      public reactor.core.publisher.Mono<Long> count(Query query, @Nullable Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns the number of documents for the given Query by querying the given collection using the given entity class to map the given Query.
      NOTE: Query offset and limit can 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 use ReactiveMongoOperations.estimatedCount(Class) for empty queries instead of running an aggregation execution which may have an impact on performance.
      Specified by:
      count in interface ReactiveMongoOperations
      Parameters:
      query - the Query class 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 reactor.core.publisher.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

      public reactor.core.publisher.Mono<Long> estimatedCount(String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Estimate 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:
      estimatedCount in interface ReactiveMongoOperations
      Parameters:
      collectionName - must not be null.
      Returns:
      a Mono emitting the estimated number of documents.
    • doEstimatedCount

      protected reactor.core.publisher.Mono<Long> doEstimatedCount(String collectionName, com.mongodb.client.model.EstimatedDocumentCountOptions options)
    • exactCount

      public reactor.core.publisher.Mono<Long> exactCount(Query query, @Nullable Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns the number of documents for the given Query by querying the given collection using the given entity class to map the given Query.
      NOTE: Query offset and limit can 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 an aggregation execution even for empty queries which may have an impact on performance, but guarantees shard, session and transaction compliance. In case an inaccurate count satisfies the applications needs use ReactiveMongoOperations.estimatedCount(String) for empty queries instead.
      Specified by:
      exactCount in interface ReactiveMongoOperations
      Parameters:
      query - the Query class 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

      protected reactor.core.publisher.Mono<Long> doExactCount(String collectionName, org.bson.Document filter, com.mongodb.client.model.CountOptions options)
    • countCanBeEstimated

      protected reactor.core.publisher.Mono<Boolean> countCanBeEstimated(org.bson.Document filter, com.mongodb.client.model.CountOptions options)
    • insert

      public <T> reactor.core.publisher.Mono<T> insert(reactor.core.publisher.Mono<? extends T> objectToSave)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version the property will be auto incremented. The operation raises an error in case the document has been modified in between.

      Specified by:
      insert in interface ReactiveMongoOperations
      Parameters:
      objectToSave - the object to store in the collection. Must not be null.
      Returns:
      the inserted objects.
    • insertAll

      public <T> reactor.core.publisher.Flux<T> insertAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> batchToSave, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      Specified by:
      insertAll in interface ReactiveMongoOperations
      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> reactor.core.publisher.Flux<T> insertAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> batchToSave, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      Specified by:
      insertAll in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Mono<T> insert(T objectToSave)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      The objectToSave must not be collection-like.

      Specified by:
      insert in interface ReactiveMongoOperations
      Parameters:
      objectToSave - the object to store in the collection. Must not be null.
      Returns:
      the inserted object.
    • insert

      public <T> reactor.core.publisher.Mono<T> insert(T objectToSave, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Insert the object into the specified collection.
      The object is converted to the MongoDB native representation using an instance of . Unless configured otherwise, an instance of MappingMongoConverter will 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 Version property initialization.

      The objectToSave must not be collection-like.

      Specified by:
      insert in interface ReactiveMongoOperations
      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

      protected <T> reactor.core.publisher.Mono<T> doInsert(String collectionName, T objectToSave, MongoWriter<Object> writer)
    • insert

      public <T> reactor.core.publisher.Flux<T> insert(Collection<? extends T> batchToSave, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      Specified by:
      insert in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Flux<T> insert(Collection<? extends T> batchToSave, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      Specified by:
      insert in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Flux<T> insertAll(Collection<? extends T> objectsToSave)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      Specified by:
      insertAll in interface ReactiveMongoOperations
      Parameters:
      objectsToSave - the list of objects to save. Must not be null.
      Returns:
      the saved objects.
    • insertAll

      public <T> reactor.core.publisher.Flux<T> insertAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> objectsToSave)
      Description copied from interface: ReactiveMongoOperations
      Insert 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 Version property initialization.

      Specified by:
      insertAll in interface ReactiveMongoOperations
      Parameters:
      objectsToSave - the publisher which provides objects to save. Must not be null.
      Returns:
      the inserted objects.
    • doInsertAll

      protected <T> reactor.core.publisher.Flux<T> doInsertAll(Collection<? extends T> listToSave, MongoWriter<Object> writer)
    • doInsertBatch

      protected <T> reactor.core.publisher.Flux<T> doInsertBatch(String collectionName, Collection<? extends T> batchToSave, MongoWriter<Object> writer)
    • save

      public <T> reactor.core.publisher.Mono<T> save(reactor.core.publisher.Mono<? extends T> objectToSave)
      Description copied from interface: ReactiveMongoOperations
      Save 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 of MappingMongoConverter will 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 Version the property will be auto incremented. The operation raises an error in case the document has been modified in between.

      Specified by:
      save in interface ReactiveMongoOperations
      Parameters:
      objectToSave - the object to store in the collection. Must not be null.
      Returns:
      the saved object.
    • save

      public <T> reactor.core.publisher.Mono<T> save(reactor.core.publisher.Mono<? extends T> objectToSave, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Save 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 of MappingMongoConverter will 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 Version the property will be auto incremented. The operation raises an error in case the document has been modified in between.

      Specified by:
      save in interface ReactiveMongoOperations
      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

      public <T> reactor.core.publisher.Mono<T> save(T objectToSave)
      Description copied from interface: ReactiveMongoOperations
      Save 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 of MappingMongoConverter will 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 Version the property will be auto incremented. The operation raises an error in case the document has been modified in between.

      The objectToSave must not be collection-like.

      Specified by:
      save in interface ReactiveMongoOperations
      Parameters:
      objectToSave - the object to store in the collection. Must not be null.
      Returns:
      the saved object.
    • save

      public <T> reactor.core.publisher.Mono<T> save(T objectToSave, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Save 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 of MappingMongoConverter will 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 Version the property will be auto incremented. The operation raises an error in case the document has been modified in between.

      Specified by:
      save in interface ReactiveMongoOperations
      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

      protected <T> reactor.core.publisher.Mono<T> doSave(String collectionName, T objectToSave, MongoWriter<Object> writer)
    • insertDocument

      protected reactor.core.publisher.Mono<Object> insertDocument(String collectionName, org.bson.Document dbDoc, Class<?> entityClass)
    • insertDocumentList

      protected reactor.core.publisher.Flux<org.bson.types.ObjectId> insertDocumentList(String collectionName, List<org.bson.Document> dbDocList)
    • saveDocument

      protected reactor.core.publisher.Mono<Object> saveDocument(String collectionName, org.bson.Document document, Class<?> entityClass)
    • upsert

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition update, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Performs 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 Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      NOTE: sorting is not supported by db.collection.updateOne. Use ReactiveMongoOperations.findAndModify(Query, UpdateDefinition, Class) instead.

      Specified by:
      upsert in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be upserted. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • upsert

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition update, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Performs 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. Use ReactiveMongoOperations.upsert(Query, UpdateDefinition, Class, String) to get full type specific support.
      Specified by:
      upsert in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be upserted. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • upsert

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Performs 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 Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      upsert in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be upserted. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • updateFirst

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Updates 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 Version property of the entityClass will be auto-incremented if not explicitly specified in the update. NOTE: sorting is not supported by db.collection.updateOne. Use ReactiveMongoOperations.findAndModify(Query, UpdateDefinition, Class) instead.

      Specified by:
      updateFirst in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be updated. Must not be null.
      update - the UpdateDefinition that contains the updated object or $ operators to manipulate the existing. Must not be null.
      entityClass - class that determines the collection to use.
      Returns:
      the UpdateResult which lets you access the results of the previous write.
      See Also:
    • updateFirst

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Updates 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. Use ReactiveMongoOperations.updateFirst(Query, UpdateDefinition, Class, String) to get full type specific support.
      NOTE: sorting is not supported by db.collection.updateOne. Use ReactiveMongoOperations.findAndModify(Query, UpdateDefinition, Class, String) instead.
      Specified by:
      updateFirst in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be updated. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • updateFirst

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.

      A potential Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      updateFirst in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be updated. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • updateMulti

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Updates 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 Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      updateMulti in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be updated. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • updateMulti

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Updates 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. Use ReactiveMongoOperations.updateMulti(Query, UpdateDefinition, Class, String) to get full type specific support.
      Specified by:
      updateMulti in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be updated. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • updateMulti

      public reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Updates 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 Version property of the entityClass will be auto-incremented if not explicitly specified in the update.

      Specified by:
      updateMulti in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to select a document to be updated. Must not be null.
      update - the UpdateDefinition that 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 UpdateResult which lets you access the results of the previous write.
      See Also:
    • doUpdate

      protected reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> doUpdate(String collectionName, Query query, @Nullable UpdateDefinition update, @Nullable Class<?> entityClass, boolean upsert, boolean multi)
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(reactor.core.publisher.Mono<? extends Object> objectToRemove)
      Description copied from interface: ReactiveMongoOperations
      Remove the given object from the collection by id and (if applicable) its Version.
      Specified by:
      remove in interface ReactiveMongoOperations
      Parameters:
      objectToRemove - must not be null.
      Returns:
      the DeleteResult which lets you access the results of the previous delete.
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(reactor.core.publisher.Mono<? extends Object> objectToRemove, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Removes the given object from the given collection by id and (if applicable) its Version.
      Specified by:
      remove in interface ReactiveMongoOperations
      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 DeleteResult which lets you access the results of the previous delete.
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Object object)
      Description copied from interface: ReactiveMongoOperations
      Remove the given object from the collection by id and (if applicable) its Version.
      Specified by:
      remove in interface ReactiveMongoOperations
      Parameters:
      object - must not be null.
      Returns:
      the DeleteResult which lets you access the results of the previous delete.
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Object object, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Removes the given object from the given collection.
      Specified by:
      remove in interface ReactiveMongoOperations
      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 DeleteResult which lets you access the results of the previous delete.
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Query query, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Remove 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. Use ReactiveMongoOperations.remove(Query, Class, String) to get full type specific support.
      Specified by:
      remove in interface ReactiveMongoOperations
      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 DeleteResult which lets you access the results of the previous delete.
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Query query, Class<?> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Remove 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:
      remove in interface ReactiveMongoOperations
      Parameters:
      query - the query document that specifies the criteria used to remove a document.
      entityClass - class that determines the collection to use.
      Returns:
      the DeleteResult which lets you access the results of the previous delete.
    • remove

      public reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Query query, @Nullable Class<?> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Remove 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:
      remove in interface ReactiveMongoOperations
      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 DeleteResult which lets you access the results of the previous delete.
    • doRemove

      protected <T> reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> doRemove(String collectionName, Query query, @Nullable Class<T> entityClass)
    • findAll

      public <T> reactor.core.publisher.Flux<T> findAll(Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Query for a Flux of 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 of MappingMongoConverter will 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:
      findAll in interface ReactiveMongoOperations
      Parameters:
      entityClass - the parametrized type of the returned Flux.
      Returns:
      the converted collection.
    • findAll

      public <T> reactor.core.publisher.Flux<T> findAll(Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Query for a Flux of 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 of MappingMongoConverter will 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:
      findAll in interface ReactiveMongoOperations
      Parameters:
      entityClass - the parametrized type of the returned Flux.
      collectionName - name of the collection to retrieve the objects from.
      Returns:
      the converted collection.
    • findAllAndRemove

      public <T> reactor.core.publisher.Flux<T> findAllAndRemove(Query query, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns 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. Use ReactiveMongoOperations.findAllAndRemove(Query, Class, String) to get full type specific support.
      Specified by:
      findAllAndRemove in interface ReactiveMongoOperations
      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 Flux converted objects deleted by this operation.
    • findAllAndRemove

      public <T> reactor.core.publisher.Flux<T> findAllAndRemove(Query query, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Returns and removes all documents matching the given query form the collection used to store the entityClass.
      Specified by:
      findAllAndRemove in interface ReactiveMongoOperations
      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 Flux converted objects deleted by this operation.
    • findAllAndRemove

      public <T> reactor.core.publisher.Flux<T> findAllAndRemove(Query query, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Returns 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:
      findAllAndRemove in interface ReactiveMongoOperations
      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 Flux converted objects deleted by this operation.
    • replace

      public <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> replace(Query query, T replacement, ReplaceOptions options, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Replace a single document matching the Criteria of given Query with the replacement document taking ReplaceOptions into account.
      Specified by:
      replace in interface ReactiveMongoOperations
      Parameters:
      query - the Query class that specifies the Criteria used to find a document. The query may * contain an index hint or the collation to use. Must not be null.
      replacement - the replacement document. Must not be null.
      options - the ReplaceOptions holding additional information. Must not be null.
      Returns:
      the UpdateResult which lets you access the results of the previous replacement.
    • replace

      protected <S, T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> replace(Query query, Class<S> entityType, T replacement, ReplaceOptions options, String collectionName)
    • tail

      public <T> reactor.core.publisher.Flux<T> tail(Query query, Class<T> entityClass)
      Description copied from interface: ReactiveMongoOperations
      Map 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 a tailable cursor that may be an infinite stream. The stream will not be completed unless the Subscription is canceled.
      The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      tail in interface ReactiveMongoOperations
      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 returned Flux.
      Returns:
      the Flux of converted objects.
    • tail

      public <T> reactor.core.publisher.Flux<T> tail(@Nullable Query query, Class<T> entityClass, String collectionName)
      Description copied from interface: ReactiveMongoOperations
      Map 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 a tailable cursor that may be an infinite stream. The stream will not be completed unless the Subscription is canceled.
      The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance of MappingMongoConverter will be used.
      The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.
      Specified by:
      tail in interface ReactiveMongoOperations
      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 returned Flux.
      collectionName - name of the collection to retrieve the objects from.
      Returns:
      the Flux of converted objects.
    • changeStream

      public <T> reactor.core.publisher.Flux<ChangeStreamEvent<T>> changeStream(@Nullable String database, @Nullable String collectionName, ChangeStreamOptions options, Class<T> targetType)
      Description copied from interface: ReactiveMongoOperations
      Subscribe to a MongoDB Change Stream via the reactive infrastructure. Use the optional provided Aggregation to filter events. The stream will not be completed unless the Subscription is canceled.
      The ChangeStreamEvent.getBody() is mapped to the resultType while the ChangeStreamEvent.getRaw() contains the unmodified payload.
      Use ChangeStreamOptions to set arguments like the resumseToken for resuming change streams.
      Specified by:
      changeStream in interface ReactiveMongoOperations
      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. Use ChangeStreamOptions.empty().
      targetType - the result type to use.
      Returns:
      the Flux emitting events as they arrive.
      See Also:
    • mapReduce

      public <T> reactor.core.publisher.Flux<T> mapReduce(Query filterQuery, Class<?> domainType, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options)
      Description copied from interface: ReactiveMongoOperations
      Execute a map-reduce operation. Use MapReduceOptions to optionally specify an output collection and other args.
      Specified by:
      mapReduce in interface ReactiveMongoOperations
      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 filter Query against. 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 Flux emitting the result document sequence. Never null.
    • mapReduce

      public <T> reactor.core.publisher.Flux<T> mapReduce(Query filterQuery, Class<?> domainType, String inputCollectionName, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options)
      Description copied from interface: ReactiveMongoOperations
      Execute a map-reduce operation. Use MapReduceOptions to optionally specify an output collection and other args.
      Specified by:
      mapReduce in interface ReactiveMongoOperations
      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 filter Query against. 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 Flux emitting the result document sequence. Never null.
    • query

      public <T> ReactiveFindOperation.ReactiveFind<T> query(Class<T> domainType)
      Description copied from interface: ReactiveFindOperation
      Start creating a find operation for the given domainType.
      Specified by:
      query in interface ReactiveFindOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of ReactiveFindOperation.ReactiveFind. Never null.
    • update

      public <T> ReactiveUpdateOperation.ReactiveUpdate<T> update(Class<T> domainType)
      Description copied from interface: ReactiveUpdateOperation
      Start creating an update operation for the given domainType.
      Specified by:
      update in interface ReactiveUpdateOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of ReactiveUpdateOperation.ReactiveUpdate. Never null.
    • remove

      public <T> ReactiveRemoveOperation.ReactiveRemove<T> remove(Class<T> domainType)
      Description copied from interface: ReactiveRemoveOperation
      Start creating a remove operation for the given domainType.
      Specified by:
      remove in interface ReactiveRemoveOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of ReactiveRemoveOperation.ReactiveRemove. Never null.
    • insert

      public <T> ReactiveInsertOperation.ReactiveInsert<T> insert(Class<T> domainType)
      Description copied from interface: ReactiveInsertOperation
      Start creating an insert operation for given domainType.
      Specified by:
      insert in interface ReactiveInsertOperation
      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: ReactiveAggregationOperation
      Start creating an aggregation operation that returns results mapped to the given domain type.
      Use TypedAggregation to specify a potentially different input type for he aggregation.
      Specified by:
      aggregateAndReturn in interface ReactiveAggregationOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of ReactiveAggregationOperation.ReactiveAggregation. Never null.
    • mapReduce

      public <T> ReactiveMapReduceOperation.ReactiveMapReduce<T> mapReduce(Class<T> domainType)
      Description copied from interface: ReactiveMapReduceOperation
      Start creating a mapReduce operation for the given domainType.
      Specified by:
      mapReduce in interface ReactiveMapReduceOperation
      Parameters:
      domainType - must not be null.
      Returns:
      new instance of ExecutableFindOperation.ExecutableFind.
    • changeStream

      public <T> ReactiveChangeStreamOperation.ReactiveChangeStream<T> changeStream(Class<T> domainType)
      Description copied from interface: ReactiveChangeStreamOperation
      Start creating a change stream operation for the given domainType watching all collections within the database.
      Consider limiting events be defining a collection and/or filter.
      Specified by:
      changeStream in interface ReactiveChangeStreamOperation
      Parameters:
      domainType - must not be null. Use Document to obtain raw elements.
      Returns:
      new instance of ReactiveChangeStreamOperation.ReactiveChangeStream. Never null.
    • doFindAndDelete

      protected <T> reactor.core.publisher.Flux<T> doFindAndDelete(String collectionName, Query query, Class<T> entityClass)
      Retrieve and remove all documents matching the given query by calling find(Query, Class, String) and remove(Query, Class, String), whereas the Query for remove(Query, Class, String) is constructed out of the find result.
      Parameters:
      collectionName -
      query -
      entityClass -
      Returns:
    • doCreateCollection

      protected reactor.core.publisher.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> reactor.core.publisher.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 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.
      collation - can be null.
      Returns:
      the List of converted objects.
    • doFindOne

      protected <T> reactor.core.publisher.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 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 - the preparer modifying collection and publisher to fit the needs.
      Returns:
      the List of converted objects.
      Since:
      2.2
    • doFind

      protected <T> reactor.core.publisher.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 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.
      Returns:
      the List of converted objects.
    • doFind

      protected <T> reactor.core.publisher.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 the FindIterable used when iterating over the result set, (apply limits, skips and so on).
      Returns:
      the List of converted objects.
    • doFind

      protected <S, T> reactor.core.publisher.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> reactor.core.publisher.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> reactor.core.publisher.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> reactor.core.publisher.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 replacement Document.
      options - applicable options.
      resultType - the target domain type.
      Returns:
      Mono.empty() if object does not exist, return new is false and upsert is false.
      Since:
      2.1
    • maybeEmitEvent

      protected <E extends MongoMappingEvent<T>, T> E maybeEmitEvent(E event)
    • maybeCallBeforeConvert

      protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeConvert(T object, String collection)
    • maybeCallBeforeSave

      protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeSave(T object, org.bson.Document document, String collection)
    • maybeCallAfterSave

      protected <T> reactor.core.publisher.Mono<T> maybeCallAfterSave(T object, org.bson.Document document, String collection)
    • maybeCallAfterConvert

      protected <T> reactor.core.publisher.Mono<T> maybeCallAfterConvert(T object, org.bson.Document document, String collection)
    • ensureNotCollectionLike

      protected void ensureNotCollectionLike(@Nullable Object source)
      Ensure the given source is not an Array, Collection or Iterator.
      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

      @Nullable protected com.mongodb.WriteConcern prepareWriteConcern(MongoAction mongoAction)
      Prepare the WriteConcern before any processing is done using it. This allows a convenient way to apply custom settings in sub-classes.
      The returned WriteConcern will be defaulted to WriteConcern.ACKNOWLEDGED when WriteResultChecking is set to WriteResultChecking.EXCEPTION.
      Parameters:
      mongoAction - any WriteConcern already configured or null.
      Returns:
      The prepared WriteConcern or null.
      See Also:
    • getMongoDatabaseFactory

      public ReactiveMongoDatabaseFactory getMongoDatabaseFactory()
      Returns:
      the MongoDatabaseFactory in use.
      Since:
      3.1.4