org.springframework.data.mongodb.core

Interface ReactiveMongoOperations

    • Method Detail

      • indexOps

        ReactiveIndexOperations indexOps(String collectionName)
        Returns the reactive operations that can be performed on indexes
        Parameters:
        collectionName - must not be null.
        Returns:
        index operations on the named collection
      • indexOps

        ReactiveIndexOperations indexOps(Class<?> entityClass)
        Returns the reactive operations that can be performed on indexes
        Parameters:
        entityClass - must not be null.
        Returns:
        index operations on the named collection associated with the given entity class
      • executeCommand

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

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

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

        <T> reactor.core.publisher.Flux<T> execute(ReactiveDatabaseCallback<T> action)
        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.

        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

        <T> reactor.core.publisher.Flux<T> execute(Class<?> entityClass,
                                                   ReactiveCollectionCallback<T> action)
        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.

        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

        <T> reactor.core.publisher.Flux<T> execute(String collectionName,
                                                   ReactiveCollectionCallback<T> action)
        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.

        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.
        action - 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

        ReactiveMongoOperations withSession(com.mongodb.reactivestreams.client.ClientSession session)
        Obtain a ClientSession bound instance of ReactiveMongoOperations.

        Note: It is up to the caller to manage the ClientSession lifecycle.

        Parameters:
        session - must not be null.
        Returns:
        ClientSession bound instance of ReactiveMongoOperations.
        Since:
        2.1
      • inTransaction

        ReactiveSessionScoped inTransaction()
        Initiate a new ClientSession and obtain a session bound instance of ReactiveSessionScoped. Starts the transaction and adds the ClientSession to each and every command issued against MongoDB.

        Each execution initiates a new managed transaction that is committed on success. Transactions are rolled back upon errors.

        Returns:
        new instance of ReactiveSessionScoped. Never null.
      • inTransaction

        ReactiveSessionScoped inTransaction(org.reactivestreams.Publisher<com.mongodb.reactivestreams.client.ClientSession> sessionProvider)
        Obtain a session bound instance of ReactiveSessionScoped, start the transaction and bind the ClientSession provided by the given Publisher to each and every command issued against MongoDB.

        Each execution initiates a new managed transaction that is committed on success. Transactions are rolled back upon errors.

        Parameters:
        sessionProvider - must not be null.
        Returns:
        new instance of ReactiveSessionScoped. Never null.
        Since:
        2.1
      • createCollection

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

        <T> reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(Class<T> entityClass,
                                                                                                                                @Nullable
                                                                                                                                CollectionOptions collectionOptions)
        Create a collection with a name based on the provided entity class using the options.
        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

        reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(String collectionName)
        Create an uncapped collection with the provided name.
        Parameters:
        collectionName - name of the collection.
        Returns:
        the created collection.
      • createCollection

        reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createCollection(String collectionName,
                                                                                                                            CollectionOptions collectionOptions)
        Create a collection with the provided name and options.
        Parameters:
        collectionName - name of the collection. Must not be null nor empty.
        collectionOptions - options to use when creating the collection.
        Returns:
        the created collection.
      • getCollectionNames

        reactor.core.publisher.Flux<String> getCollectionNames()
        A set of collection names.
        Returns:
        Flux of collection names.
      • getCollection

        com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> getCollection(String collectionName)
        Get a collection by name, creating it if it doesn't exist.

        Translate any exceptions as necessary.

        Parameters:
        collectionName - name of the collection.
        Returns:
        an existing collection or a newly created one.
      • collectionExists

        <T> reactor.core.publisher.Mono<Boolean> collectionExists(Class<T> entityClass)
        Check to see if a collection with a name indicated by the entity class exists.

        Translate any exceptions as necessary.

        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

        reactor.core.publisher.Mono<Boolean> collectionExists(String collectionName)
        Check to see if a collection with a given name exists.

        Translate any exceptions as necessary.

        Parameters:
        collectionName - name of the collection. Must not be null.
        Returns:
        true if a collection with the given name is found, false otherwise.
      • dropCollection

        <T> reactor.core.publisher.Mono<Void> dropCollection(Class<T> entityClass)
        Drop the collection with the name indicated by the entity class.

        Translate any exceptions as necessary.

        Parameters:
        entityClass - class that determines the collection to drop/delete. Must not be null.
      • dropCollection

        reactor.core.publisher.Mono<Void> dropCollection(String collectionName)
        Drop the collection with the given name.

        Translate any exceptions as necessary.

        Parameters:
        collectionName - name of the collection to drop/delete.
      • findAll

        <T> reactor.core.publisher.Flux<T> findAll(Class<T> entityClass)
        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 MongoConverter. 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.

        Parameters:
        entityClass - the parametrized type of the returned Flux.
        Returns:
        the converted collection.
      • findAll

        <T> reactor.core.publisher.Flux<T> findAll(Class<T> entityClass,
                                                   String collectionName)
        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 MongoConverter. 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.

        Parameters:
        entityClass - the parametrized type of the returned Flux.
        collectionName - name of the collection to retrieve the objects from.
        Returns:
        the converted collection.
      • findOne

        <T> reactor.core.publisher.Mono<T> findOne(Query query,
                                                   Class<T> entityClass)
        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 MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record and also an optional fields specification.
        entityClass - the parametrized type of the returned Mono.
        Returns:
        the converted object.
      • findOne

        <T> reactor.core.publisher.Mono<T> findOne(Query query,
                                                   Class<T> entityClass,
                                                   String collectionName)
        Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type.

        The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record 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

        reactor.core.publisher.Mono<Boolean> exists(Query query,
                                                    String collectionName)
        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 exists(Query, Class, String) to get full type specific support.
        Parameters:
        query - the Query class that specifies the criteria used to find a record.
        collectionName - name of the collection to check for objects.
        Returns:
        true if the query yields a result.
      • exists

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

        reactor.core.publisher.Mono<Boolean> exists(Query query,
                                                    @Nullable
                                                    Class<?> entityClass,
                                                    String collectionName)
        Determine result of given Query contains at least one element.
        Parameters:
        query - the Query class that specifies the criteria used to find a record.
        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

        <T> reactor.core.publisher.Flux<T> find(Query query,
                                                Class<T> entityClass)
        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 MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record 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

        <T> reactor.core.publisher.Flux<T> find(Query query,
                                                Class<T> entityClass,
                                                String collectionName)
        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 MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record 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.
      • findById

        <T> reactor.core.publisher.Mono<T> findById(Object id,
                                                    Class<T> entityClass)
        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.
        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

        <T> reactor.core.publisher.Mono<T> findById(Object id,
                                                    Class<T> entityClass,
                                                    String collectionName)
        Returns the document with the given id from the given collection mapped onto the given target class.
        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

        default <T> reactor.core.publisher.Flux<T> findDistinct(String field,
                                                                Class<?> entityClass,
                                                                Class<T> resultClass)
        Finds the distinct values for a specified field across a single MongoCollection or view and returns the results in a Flux.
        Parameters:
        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. Must not be null.
        resultClass - the result type. Must not be null.
        Returns:
        never null.
        Since:
        2.1
      • findDistinct

        <T> reactor.core.publisher.Flux<T> findDistinct(Query query,
                                                        String field,
                                                        Class<?> entityClass,
                                                        Class<T> resultClass)
        Finds the distinct values for a specified field across a single MongoCollection or view and returns the results in a Flux.
        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.
        Since:
        2.1
      • findDistinct

        <T> reactor.core.publisher.Flux<T> findDistinct(Query query,
                                                        String field,
                                                        String collectionName,
                                                        Class<?> entityClass,
                                                        Class<T> resultClass)
        Finds the distinct values for a specified field across a single MongoCollection or view and returns the results in a Flux.
        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.
        Since:
        2.1
      • findDistinct

        default <T> reactor.core.publisher.Flux<T> findDistinct(Query query,
                                                                String field,
                                                                String collection,
                                                                Class<T> resultClass)
        Finds the distinct values for a specified field across a single MongoCollection or view and returns the results in a Flux.
        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.
        collection - the explicit name of the actual MongoCollection. Must not be null.
        resultClass - the result type. Must not be null.
        Returns:
        never null.
        Since:
        2.1
      • aggregate

        <O> reactor.core.publisher.Flux<O> aggregate(TypedAggregation<?> aggregation,
                                                     String collectionName,
                                                     Class<O> outputType)
        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.

        Parameters:
        aggregation - The TypedAggregation specification holding the aggregation operations. Must not be null.
        collectionName - 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.
        Throws:
        IllegalArgumentException - if aggregation, collectionName or outputType is null.
      • aggregate

        <O> reactor.core.publisher.Flux<O> aggregate(Aggregation aggregation,
                                                     Class<?> inputType,
                                                     Class<O> outputType)
        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.

        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.
        Throws:
        IllegalArgumentException - if aggregation, inputType or outputType is null.
      • aggregate

        <O> reactor.core.publisher.Flux<O> aggregate(Aggregation aggregation,
                                                     String collectionName,
                                                     Class<O> outputType)
        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.

        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.
        Throws:
        IllegalArgumentException - if aggregation, collectionName or outputType is null.
      • geoNear

        <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near,
                                                              Class<T> entityClass)
        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.
        Parameters:
        near - must not be null.
        entityClass - must not be null.
        Returns:
        the converted GeoResults.
      • geoNear

        <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near,
                                                              Class<T> entityClass,
                                                              String collectionName)
        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.
        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.
      • findAndModify

        <T> reactor.core.publisher.Mono<T> findAndModify(Query query,
                                                         Update update,
                                                         Class<T> entityClass)
        Triggers findAndModify to apply provided Update on documents matching Criteria of given Query.
        Parameters:
        query - the Query class that specifies the Criteria used to find a record and also an optional fields specification. Must not be null.
        update - the Update 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.
      • findAndModify

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

        default <T> reactor.core.publisher.Mono<T> findAndReplace(Query query,
                                                                  T replacement)
        Triggers findOneAndReplace to replace a single document matching Criteria of given Query with the replacement document.
        Options are defaulted to FindAndReplaceOptions.empty().
        NOTE: The replacement entity must not hold an id.
        Parameters:
        query - the Query class that specifies the Criteria used to find a record and also an optional fields specification. Must not be null.
        replacement - the replacement document. Must not be null.
        Returns:
        the converted object that was updated or Mono.empty(), if not found.
        Since:
        2.1
      • findAndReplace

        default <T> reactor.core.publisher.Mono<T> findAndReplace(Query query,
                                                                  T replacement,
                                                                  String collectionName)
        Triggers findOneAndReplace to replace a single document matching Criteria of given Query with the replacement document.
        Options are defaulted to FindAndReplaceOptions.empty().
        NOTE: The replacement entity must not hold an id.
        Parameters:
        query - the Query class that specifies the Criteria used to find a record and also an optional fields specification. Must not be null.
        replacement - the replacement document. Must not be null.
        collectionName - the collection to query. Must not be null.
        Returns:
        the converted object that was updated or Mono.empty(), if not found.
        Since:
        2.1
      • findAndReplace

        default <T> reactor.core.publisher.Mono<T> findAndReplace(Query query,
                                                                  T replacement,
                                                                  FindAndReplaceOptions options,
                                                                  Class<T> entityType,
                                                                  String collectionName)
        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.
        Parameters:
        query - the Query class that specifies the Criteria used to find a record 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 parametrized type. Must not be null.
        collectionName - the collection to query. Must not be null.
        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.
        Since:
        2.1
      • findAndReplace

        default <S,T> reactor.core.publisher.Mono<T> findAndReplace(Query query,
                                                                    S replacement,
                                                                    FindAndReplaceOptions options,
                                                                    Class<S> entityType,
                                                                    Class<T> resultType)
        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.
        Parameters:
        query - the Query class that specifies the Criteria used to find a record 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.
        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.
        Since:
        2.1
      • findAndReplace

        <S,T> reactor.core.publisher.Mono<T> findAndReplace(Query query,
                                                            S replacement,
                                                            FindAndReplaceOptions options,
                                                            Class<S> entityType,
                                                            String collectionName,
                                                            Class<T> resultType)
        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.
        Parameters:
        query - the Query class that specifies the Criteria used to find a record 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.
        Since:
        2.1
      • findAndRemove

        <T> reactor.core.publisher.Mono<T> findAndRemove(Query query,
                                                         Class<T> entityClass)
        Map the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the specified type. 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 MongoConverter.

        The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

        Parameters:
        query - the query class that specifies the criteria used to find a record and also an optional fields specification.
        entityClass - the parametrized type of the returned Mono.
        Returns:
        the converted object
      • findAndRemove

        <T> reactor.core.publisher.Mono<T> findAndRemove(Query query,
                                                         Class<T> entityClass,
                                                         String collectionName)
        Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. 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 MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record 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

        reactor.core.publisher.Mono<Long> count(Query query,
                                                Class<?> entityClass)
        Returns the number of documents for the given Query by querying the collection of the given entity class.
        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.
      • count

        reactor.core.publisher.Mono<Long> count(Query query,
                                                String collectionName)
        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 count(Query, Class, String) to get full type specific support.
        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(Query, Class, String)
      • count

        reactor.core.publisher.Mono<Long> count(Query query,
                                                @Nullable
                                                Class<?> entityClass,
                                                String collectionName)
        Returns the number of documents for the given Query by querying the given collection using the given entity class to map the given Query.
        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.
      • insert

        <T> reactor.core.publisher.Mono<T> insert(T objectToSave)
        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 MongoConverter.

        If you 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.

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

        <T> reactor.core.publisher.Mono<T> insert(T objectToSave,
                                                  String collectionName)
        Insert the object into the specified collection.

        The object is converted to the MongoDB native representation using an instance of MongoConverter. 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.

        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.
      • insert

        <T> reactor.core.publisher.Flux<T> insert(Collection<? extends T> batchToSave,
                                                  Class<?> entityClass)
        Insert a Collection of objects into a collection in a single batch write to the database.
        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

        <T> reactor.core.publisher.Flux<T> insert(Collection<? extends T> batchToSave,
                                                  String collectionName)
        Insert a batch of objects into the specified collection in a single batch write to the database.
        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

        <T> reactor.core.publisher.Flux<T> insertAll(Collection<? extends T> objectsToSave)
        Insert a mixed Collection of objects into a database collection determining the collection name to use based on the class.
        Parameters:
        objectsToSave - the list of objects to save. Must not be null.
        Returns:
        the saved objects.
      • insert

        <T> reactor.core.publisher.Mono<T> insert(reactor.core.publisher.Mono<? extends T> objectToSave)
        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 MongoConverter.

        If you 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.

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

        <T> reactor.core.publisher.Flux<T> insertAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> batchToSave,
                                                     Class<?> entityClass)
        Insert a Collection of objects into a collection in a single batch write to the database.
        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

        <T> reactor.core.publisher.Flux<T> insertAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> batchToSave,
                                                     String collectionName)
        Insert objects into the specified collection in a single batch write to the database.
        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.
      • insertAll

        <T> reactor.core.publisher.Flux<T> insertAll(reactor.core.publisher.Mono<? extends Collection<? extends T>> objectsToSave)
        Insert a mixed Collection of objects into a database collection determining the collection name to use based on the class.
        Parameters:
        objectsToSave - the publisher which provides objects to save. Must not be null.
        Returns:
        the inserted objects.
      • save

        <T> reactor.core.publisher.Mono<T> save(T objectToSave)
        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 MongoConverter. Unless configured otherwise, an instance of MappingMongoConverter will be used.

        If you 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.

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

        <T> reactor.core.publisher.Mono<T> save(T objectToSave,
                                                String collectionName)
        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 MongoConverter. Unless configured otherwise, an instance of MappingMongoConverter will be used.

        If you 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.

        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.
      • save

        <T> reactor.core.publisher.Mono<T> save(reactor.core.publisher.Mono<? extends T> objectToSave)
        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 MongoConverter. Unless configured otherwise, an instance of MappingMongoConverter will be used.

        If you 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.

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

        <T> reactor.core.publisher.Mono<T> save(reactor.core.publisher.Mono<? extends T> objectToSave,
                                                String collectionName)
        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 MongoConverter. Unless configured otherwise, an instance of MappingMongoConverter will be used.

        If you 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.

        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.
      • upsert

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query,
                                                                                   Update update,
                                                                                   Class<?> entityClass)
        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.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be upserted. Must not be null.
        update - the update document 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.
      • upsert

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query,
                                                                                   Update update,
                                                                                   String collectionName)
        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 upsert(Query, Update, Class, String) to get full type specific support.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be upserted. Must not be null.
        update - the update document 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.
      • upsert

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query,
                                                                                   Update update,
                                                                                   Class<?> entityClass,
                                                                                   String collectionName)
        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.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be upserted. Must not be null.
        update - the update document 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.
      • updateFirst

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query,
                                                                                        Update update,
                                                                                        Class<?> entityClass)
        Updates the first object that is found in the collection of the entity class that matches the query document with the provided update document.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be updated. Must not be null.
        update - the update document 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.
      • updateFirst

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query,
                                                                                        Update update,
                                                                                        String collectionName)
        Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.
        NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of domain type information. Use updateFirst(Query, Update, Class, String) to get full type specific support.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be updated. Must not be null.
        update - the update document 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.
      • updateFirst

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query,
                                                                                        Update update,
                                                                                        Class<?> entityClass,
                                                                                        String collectionName)
        Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be updated. Must not be null.
        update - the update document 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.
      • updateMulti

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query,
                                                                                        Update update,
                                                                                        Class<?> entityClass)
        Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be updated. Must not be null.
        update - the update document 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.
      • updateMulti

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query,
                                                                                        Update update,
                                                                                        String collectionName)
        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 updateMulti(Query, Update, Class, String) to get full type specific support.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be updated. Must not be null.
        update - the update document 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.
      • updateMulti

        reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query,
                                                                                        Update update,
                                                                                        Class<?> entityClass,
                                                                                        String collectionName)
        Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.
        Parameters:
        query - the query document that specifies the criteria used to select a record to be updated. Must not be null.
        update - the update document 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.
      • remove

        reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Object object)
        Remove the given object from the collection by id.
        Parameters:
        object - must not be null.
        Returns:
        the DeleteResult which lets you access the results of the previous delete.
      • remove

        reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Object object,
                                                                                   String collectionName)
        Removes the given object from the given collection.
        Parameters:
        object - must not be null.
        collectionName - name of the collection where the objects will removed, must not be null or empty.
        Returns:
        the DeleteResult which lets you access the results of the previous delete.
      • remove

        reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(reactor.core.publisher.Mono<? extends Object> objectToRemove)
        Remove the given object from the collection by id.
        Parameters:
        objectToRemove - must not be null.
        Returns:
        the DeleteResult which lets you access the results of the previous delete.
      • remove

        reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(reactor.core.publisher.Mono<? extends Object> objectToRemove,
                                                                                   String collectionName)
        Removes the given object from the given collection.
        Parameters:
        objectToRemove - must not be null.
        collectionName - name of the collection where the objects will removed, must not be null or empty.
        Returns:
        the DeleteResult which lets you access the results of the previous delete.
      • remove

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

        reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Query query,
                                                                                   @Nullable
                                                                                   Class<?> entityClass,
                                                                                   String collectionName)
        Remove all documents that match the provided query document criteria from the 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.
        Parameters:
        query - the query document that specifies the criteria used to remove a record.
        entityClass - class of the pojo to be operated on. Can be null.
        collectionName - name of the collection where the objects will removed, must not be null or empty.
        Returns:
        the DeleteResult which lets you access the results of the previous delete.
      • remove

        reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult> remove(Query query,
                                                                                   String collectionName)
        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 remove(Query, Class, String) to get full type specific support.
        Parameters:
        query - the query document that specifies the criteria used to remove a record.
        collectionName - name of the collection where the objects will removed, must not be null or empty.
        Returns:
        the DeleteResult which lets you access the results of the previous delete.
      • findAllAndRemove

        <T> reactor.core.publisher.Flux<T> findAllAndRemove(Query query,
                                                            String collectionName)
        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 findAllAndRemove(Query, Class, String) to get full type specific support.
        Parameters:
        query - the query document that specifies the criteria used to find and remove documents.
        collectionName - name of the collection where the objects will removed, must not be null or empty.
        Returns:
        the Flux converted objects deleted by this operation.
      • findAllAndRemove

        <T> reactor.core.publisher.Flux<T> findAllAndRemove(Query query,
                                                            Class<T> entityClass)
        Returns and removes all documents matching the given query form the collection used to store the entityClass.
        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

        <T> reactor.core.publisher.Flux<T> findAllAndRemove(Query query,
                                                            Class<T> entityClass,
                                                            String collectionName)
        Returns and removes all documents that match the provided query document criteria from the 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.
        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 objects will removed, must not be null or empty.
        Returns:
        the Flux converted objects deleted by this operation.
      • tail

        <T> reactor.core.publisher.Flux<T> tail(Query query,
                                                Class<T> entityClass)
        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 MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record and also an optional fields specification.
        entityClass - the parametrized type of the returned Flux.
        Returns:
        the Flux of converted objects.
      • tail

        <T> reactor.core.publisher.Flux<T> tail(Query query,
                                                Class<T> entityClass,
                                                String collectionName)
        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 MongoConverter. 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.

        Parameters:
        query - the query class that specifies the criteria used to find a record 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.
      • mapReduce

        <T> reactor.core.publisher.Flux<T> mapReduce(Query filterQuery,
                                                     Class<?> domainType,
                                                     Class<T> resultType,
                                                     String mapFunction,
                                                     String reduceFunction,
                                                     MapReduceOptions options)
        Execute a map-reduce operation. Use MapReduceOptions to optionally specify an output collection and other args.
        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.
        Since:
        2.1
      • mapReduce

        <T> reactor.core.publisher.Flux<T> mapReduce(Query filterQuery,
                                                     Class<?> domainType,
                                                     String inputCollectionName,
                                                     Class<T> resultType,
                                                     String mapFunction,
                                                     String reduceFunction,
                                                     MapReduceOptions options)
        Execute a map-reduce operation. Use MapReduceOptions to optionally specify an output collection and other args.
        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.
        Since:
        2.1
      • getCollectionName

        String getCollectionName(Class<?> entityClass)
        The collection name used for the specified class by this template.
        Parameters:
        entityClass - must not be null.
        Returns:
        Since:
        2.1