Interface ReactiveMongoOperations
- All Superinterfaces:
ReactiveAggregationOperation
,ReactiveChangeStreamOperation
,ReactiveFindOperation
,ReactiveFluentMongoOperations
,ReactiveInsertOperation
,ReactiveMapReduceOperation
,ReactiveRemoveOperation
,ReactiveUpdateOperation
- All Known Implementing Classes:
ReactiveMongoTemplate
Implemented by ReactiveMongoTemplate
. Not often used but a useful option for extensibility and testability
(as it can be easily mocked, stubbed, or be the target of a JDK proxy). Command execution using
ReactiveMongoOperations
is deferred until subscriber subscribes to the Publisher
.
NOTE: Some operations cannot be executed within a MongoDB transaction. Please refer to the MongoDB
specific documentation to learn more about Multi
Document Transactions.
- Since:
- 2.0
- Author:
- Mark Paluch, Christoph Strobl, Mathieu Ouellet
- See Also:
-
Flux
Mono
- Project Reactor
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveAggregationOperation
ReactiveAggregationOperation.AggregationOperationWithAggregation<T>, ReactiveAggregationOperation.AggregationOperationWithCollection<T>, ReactiveAggregationOperation.ReactiveAggregation<T>, ReactiveAggregationOperation.TerminatingAggregationOperation<T>
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveChangeStreamOperation
ReactiveChangeStreamOperation.ChangeStreamWithCollection<T>, ReactiveChangeStreamOperation.ChangeStreamWithFilterAndProjection<T>, ReactiveChangeStreamOperation.ChangeStreamWithOptions<T>, ReactiveChangeStreamOperation.ReactiveChangeStream<T>, ReactiveChangeStreamOperation.ResumingChangeStream<T>, ReactiveChangeStreamOperation.TerminatingChangeStream<T>
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveFindOperation
ReactiveFindOperation.DistinctWithProjection, ReactiveFindOperation.DistinctWithQuery<T>, ReactiveFindOperation.FindDistinct, ReactiveFindOperation.FindWithCollection<T>, ReactiveFindOperation.FindWithProjection<T>, ReactiveFindOperation.FindWithQuery<T>, ReactiveFindOperation.ReactiveFind<T>, ReactiveFindOperation.TerminatingDistinct<T>, ReactiveFindOperation.TerminatingFind<T>, ReactiveFindOperation.TerminatingFindNear<T>
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveInsertOperation
ReactiveInsertOperation.InsertWithCollection<T>, ReactiveInsertOperation.ReactiveInsert<T>, ReactiveInsertOperation.TerminatingInsert<T>
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveMapReduceOperation
ReactiveMapReduceOperation.MapReduceWithCollection<T>, ReactiveMapReduceOperation.MapReduceWithMapFunction<T>, ReactiveMapReduceOperation.MapReduceWithOptions<T>, ReactiveMapReduceOperation.MapReduceWithProjection<T>, ReactiveMapReduceOperation.MapReduceWithQuery<T>, ReactiveMapReduceOperation.MapReduceWithReduceFunction<T>, ReactiveMapReduceOperation.ReactiveMapReduce<T>, ReactiveMapReduceOperation.TerminatingMapReduce<T>
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveRemoveOperation
ReactiveRemoveOperation.ReactiveRemove<T>, ReactiveRemoveOperation.RemoveWithCollection<T>, ReactiveRemoveOperation.RemoveWithQuery<T>, ReactiveRemoveOperation.TerminatingRemove<T>
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.core.ReactiveUpdateOperation
ReactiveUpdateOperation.FindAndModifyWithOptions<T>, ReactiveUpdateOperation.FindAndReplaceWithOptions<T>, ReactiveUpdateOperation.FindAndReplaceWithProjection<T>, ReactiveUpdateOperation.ReactiveUpdate<T>, ReactiveUpdateOperation.ReplaceWithOptions, ReactiveUpdateOperation.TerminatingFindAndModify<T>, ReactiveUpdateOperation.TerminatingFindAndReplace<T>, ReactiveUpdateOperation.TerminatingReplace, ReactiveUpdateOperation.TerminatingUpdate<T>, ReactiveUpdateOperation.UpdateWithCollection<T>, ReactiveUpdateOperation.UpdateWithQuery<T>, ReactiveUpdateOperation.UpdateWithUpdate<T>
-
Method Summary
Modifier and TypeMethodDescription<O> reactor.core.publisher.Flux<O>
aggregate
(Aggregation aggregation, Class<?> inputType, Class<O> outputType) Execute an aggregation operation.<O> reactor.core.publisher.Flux<O>
aggregate
(Aggregation aggregation, String collectionName, Class<O> outputType) Execute an aggregation operation.<O> reactor.core.publisher.Flux<O>
aggregate
(TypedAggregation<?> aggregation, Class<O> outputType) Execute an aggregation operation.<O> reactor.core.publisher.Flux<O>
aggregate
(TypedAggregation<?> aggregation, String collectionName, Class<O> outputType) Execute an aggregation operation.bulkOps
(BulkOperations.BulkMode mode, Class<?> entityClass) Returns a newReactiveBulkOperations
for the given entity type.bulkOps
(BulkOperations.BulkMode mode, Class<?> entityType, String collectionName) Returns a newReactiveBulkOperations
for the given entity type and collection name.bulkOps
(BulkOperations.BulkMode mode, String collectionName) Returns a newReactiveBulkOperations
for the given collection.<T> reactor.core.publisher.Flux<ChangeStreamEvent<T>>
changeStream
(String database, String collectionName, ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream via the reactive infrastructure.default <T> reactor.core.publisher.Flux<ChangeStreamEvent<T>>
changeStream
(String collectionName, ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream for all events in the given collection via the reactive infrastructure.default <T> reactor.core.publisher.Flux<ChangeStreamEvent<T>>
changeStream
(ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream for all events in the configured default database via the reactive infrastructure.<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.reactor.core.publisher.Mono<Boolean>
collectionExists
(String collectionName) Check to see if a collection with a given name exists.reactor.core.publisher.Mono<Long>
Returns the number of documents for the givenQuery
by querying the collection of the given entity class.reactor.core.publisher.Mono<Long>
reactor.core.publisher.Mono<Long>
Returns the number of documents for the givenQuery
querying the given collection.<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.<T> reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
createCollection
(Class<T> entityClass, CollectionOptions collectionOptions) Create a collection with a name based on the provided entity class using the options.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
createCollection
(String collectionName) Create an uncapped collection with the provided name.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.default reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
createView
(String name, Class<?> source, AggregationOperation... stages) Create a view with the provided name.default reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
createView
(String name, Class<?> source, AggregationPipeline pipeline) Create a view with the provided name.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
createView
(String name, Class<?> source, AggregationPipeline pipeline, ViewOptions options) Create a view with the provided name.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
createView
(String name, String source, AggregationPipeline pipeline, ViewOptions options) Create a view with the provided name.<T> reactor.core.publisher.Mono<Void>
dropCollection
(Class<T> entityClass) Drop the collection with the name indicated by the entity class.reactor.core.publisher.Mono<Void>
dropCollection
(String collectionName) Drop the collection with the given name.default reactor.core.publisher.Mono<Long>
estimatedCount
(Class<?> entityClass) Estimate the number of documents, in the collectionidentified by the given type
, based on collection statistics.reactor.core.publisher.Mono<Long>
estimatedCount
(String collectionName) Estimate the number of documents in the given collection based on collection statistics.default reactor.core.publisher.Mono<Long>
exactCount
(Query query, Class<?> entityClass) Returns the number of documents for the givenQuery
by querying the collection of the given entity class.reactor.core.publisher.Mono<Long>
exactCount
(Query query, Class<?> entityClass, String collectionName) default reactor.core.publisher.Mono<Long>
exactCount
(Query query, String collectionName) Returns the number of documents for the givenQuery
querying the given collection.<T> reactor.core.publisher.Flux<T>
execute
(Class<?> entityClass, ReactiveCollectionCallback<T> action) Executes the givenReactiveCollectionCallback
on the entity collection of the specified class.<T> reactor.core.publisher.Flux<T>
execute
(String collectionName, ReactiveCollectionCallback<T> action) Executes the givenReactiveCollectionCallback
on the collection of the given name.<T> reactor.core.publisher.Flux<T>
execute
(ReactiveDatabaseCallback<T> action) Executes aReactiveDatabaseCallback
translating any exceptions as necessary.reactor.core.publisher.Mono<org.bson.Document>
executeCommand
(String jsonCommand) Execute a MongoDB command expressed as a JSON string.reactor.core.publisher.Mono<org.bson.Document>
executeCommand
(org.bson.Document command) Execute a MongoDB command.reactor.core.publisher.Mono<org.bson.Document>
executeCommand
(org.bson.Document command, com.mongodb.ReadPreference readPreference) Execute a MongoDB command.reactor.core.publisher.Mono<Boolean>
Determine result of givenQuery
contains at least one element.reactor.core.publisher.Mono<Boolean>
Determine result of givenQuery
contains at least one element.reactor.core.publisher.Mono<Boolean>
Determine result of givenQuery
contains at least one element.<T> reactor.core.publisher.Flux<T>
Map the results of an ad-hoc query on the collection for the entity class to aFlux
of the specified type.<T> reactor.core.publisher.Flux<T>
Map the results of an ad-hoc query on the specified collection to aFlux
of the specified type.<T> reactor.core.publisher.Flux<T>
Query for aFlux
of objects of type T from the collection used by the entity class.<T> reactor.core.publisher.Flux<T>
Query for aFlux
of objects of type T from the specified collection.<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.<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 collection used to store the entityClass.<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.<T> reactor.core.publisher.Mono<T>
findAndModify
(Query query, UpdateDefinition update, Class<T> entityClass) <T> reactor.core.publisher.Mono<T>
findAndModify
(Query query, UpdateDefinition update, Class<T> entityClass, String collectionName) <T> reactor.core.publisher.Mono<T>
findAndModify
(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass) Triggers findAndModify to apply providedUpdate
on documents matchingCriteria
of givenQuery
takingFindAndModifyOptions
into account.<T> reactor.core.publisher.Mono<T>
findAndModify
(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass, String collectionName) Triggers findAndModify to apply providedUpdate
on documents matchingCriteria
of givenQuery
takingFindAndModifyOptions
into account.<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.<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.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 matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.<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 matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.default <T> reactor.core.publisher.Mono<T>
findAndReplace
(Query query, T replacement) Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document.default <T> reactor.core.publisher.Mono<T>
findAndReplace
(Query query, T replacement, String collectionName) Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document.default <T> reactor.core.publisher.Mono<T>
findAndReplace
(Query query, T replacement, FindAndReplaceOptions options) Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.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 matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.default <T> reactor.core.publisher.Mono<T>
findAndReplace
(Query query, T replacement, FindAndReplaceOptions options, String collectionName) Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.<T> reactor.core.publisher.Mono<T>
Returns a document with the given id mapped onto the given class.<T> reactor.core.publisher.Mono<T>
Returns the document with the given id from the given collection mapped onto the given target class.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 singleMongoCollection
or view and returns the results in aFlux
.<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 singleMongoCollection
or view and returns the results in aFlux
.<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 singleMongoCollection
or view and returns the results in aFlux
.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 singleMongoCollection
or view and returns the results in aFlux
.<T> reactor.core.publisher.Mono<T>
Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the specified type.<T> reactor.core.publisher.Mono<T>
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type.<T> reactor.core.publisher.Flux<GeoResult<T>>
Deprecated.since 2.2.<T> reactor.core.publisher.Flux<GeoResult<T>>
Deprecated.since 2.2.reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>>
getCollection
(String collectionName) Get aMongoCollection
by name.getCollectionName
(Class<?> entityClass) The collection name used for the specified class by this template.reactor.core.publisher.Flux<String>
A set of collection names.Returns the underlyingMongoConverter
.Returns the reactive operations that can be performed on indexesReturns the reactive operations that can be performed on indexes<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.<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.<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.<T> reactor.core.publisher.Mono<T>
insert
(T objectToSave) Insert the object into the collection for the entity type of the object to save.<T> reactor.core.publisher.Mono<T>
Insert the object into the specified collection.<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.<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.<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.<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.<T> reactor.core.publisher.Flux<T>
mapReduce
(Query filterQuery, Class<?> domainType, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Deprecated.since 3.4 in favor ofaggregate(TypedAggregation, Class)
.<T> reactor.core.publisher.Flux<T>
mapReduce
(Query filterQuery, Class<?> domainType, String inputCollectionName, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Deprecated.since 3.4 in favor ofaggregate(TypedAggregation, Class)
.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Remove the given object from the collection by id and (if applicable) itsVersion
.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Removes the given object from the given collection.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Remove all documents that match the provided query document criteria from the collection used to store the entityClass.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Remove all documents that match the provided query document criteria from the collection used to store the entityClass.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Remove all documents from the specified collection that match the provided query document criteria.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Remove the given object from the collection by id and (if applicable) itsVersion
.reactor.core.publisher.Mono<com.mongodb.client.result.DeleteResult>
Removes the given object from the given collection by id and (if applicable) itsVersion
.default <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
default <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
default <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
replace
(Query query, T replacement, ReplaceOptions options) Replace a single document matching theCriteria
of givenQuery
with thereplacement
document takingReplaceOptions
into account.<T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
replace
(Query query, T replacement, ReplaceOptions options, String collectionName) Replace a single document matching theCriteria
of givenQuery
with thereplacement
document takingReplaceOptions
into account.<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.<T> reactor.core.publisher.Mono<T>
Save the object to the specified collection.<T> reactor.core.publisher.Mono<T>
save
(T objectToSave) Save the object to the collection for the entity type of the object to save.<T> reactor.core.publisher.Mono<T>
Save the object to the specified collection.<T> reactor.core.publisher.Mono<Window<T>>
Query for a scroll of objects of type T from the specified collection.<T> reactor.core.publisher.Mono<Window<T>>
Query for a window of objects of type T from the specified collection.<T> reactor.core.publisher.Flux<T>
Map the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified type.<T> reactor.core.publisher.Flux<T>
Map the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified type.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
updateFirst
(Query query, UpdateDefinition update, Class<?> entityClass) Updates the first object that is found in the collection of the entity class that matches the query document with the provided update document.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
updateFirst
(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
updateFirst
(Query query, UpdateDefinition update, String collectionName) Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
updateMulti
(Query query, UpdateDefinition update, Class<?> entityClass) Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
updateMulti
(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
updateMulti
(Query query, UpdateDefinition update, String collectionName) Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
upsert
(Query query, UpdateDefinition update, Class<?> entityClass) Performs an upsert.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
upsert
(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Performs an upsert.reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult>
upsert
(Query query, UpdateDefinition update, String collectionName) Performs an upsert.withSession
(com.mongodb.ClientSessionOptions sessionOptions) Obtain asession
bound instance ofSessionScoped
binding a newClientSession
with given sessionOptions to each and every command issued against MongoDB.withSession
(com.mongodb.reactivestreams.client.ClientSession session) Obtain aClientSession
bound instance ofReactiveMongoOperations
.default ReactiveSessionScoped
withSession
(Supplier<com.mongodb.reactivestreams.client.ClientSession> sessionProvider) Obtain asession
bound instance ofSessionScoped
binding theClientSession
provided by the givenSupplier
to each and every command issued against MongoDB.withSession
(org.reactivestreams.Publisher<com.mongodb.reactivestreams.client.ClientSession> sessionProvider) Obtain asession
bound instance ofReactiveSessionScoped
binding theClientSession
provided by the givenPublisher
to each and every command issued against MongoDB.Methods inherited from interface org.springframework.data.mongodb.core.ReactiveAggregationOperation
aggregateAndReturn
Methods inherited from interface org.springframework.data.mongodb.core.ReactiveChangeStreamOperation
changeStream
Methods inherited from interface org.springframework.data.mongodb.core.ReactiveFindOperation
query
Methods inherited from interface org.springframework.data.mongodb.core.ReactiveInsertOperation
insert
Methods inherited from interface org.springframework.data.mongodb.core.ReactiveMapReduceOperation
mapReduce
Methods inherited from interface org.springframework.data.mongodb.core.ReactiveRemoveOperation
remove
Methods inherited from interface org.springframework.data.mongodb.core.ReactiveUpdateOperation
update
-
Method Details
-
indexOps
Returns the reactive operations that can be performed on indexes- Parameters:
collectionName
- must not be null.- Returns:
- index operations on the named collection
-
indexOps
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
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.- 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
Executes aReactiveDatabaseCallback
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 givenReactiveCollectionCallback
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 givenReactiveCollectionCallback
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 whichMongoCollection
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
default ReactiveSessionScoped withSession(Supplier<com.mongodb.reactivestreams.client.ClientSession> sessionProvider) Obtain asession
bound instance ofSessionScoped
binding theClientSession
provided by the givenSupplier
to each and every command issued against MongoDB.
Note: It is up to the caller to manage theClientSession
lifecycle. UseReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer)
to provide a hook for processing theClientSession
when done.- Parameters:
sessionProvider
- must not be null.- Returns:
- new instance of
ReactiveSessionScoped
. Never null. - Since:
- 2.1
-
withSession
Obtain asession
bound instance ofSessionScoped
binding a newClientSession
with given sessionOptions to each and every command issued against MongoDB.
Note: It is up to the caller to manage theClientSession
lifecycle. UseReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer)
to provide a hook for processing theClientSession
when done.- Parameters:
sessionOptions
- must not be null.- Returns:
- new instance of
ReactiveSessionScoped
. Never null. - Since:
- 2.1
-
withSession
ReactiveSessionScoped withSession(org.reactivestreams.Publisher<com.mongodb.reactivestreams.client.ClientSession> sessionProvider) Obtain asession
bound instance ofReactiveSessionScoped
binding theClientSession
provided by the givenPublisher
to each and every command issued against MongoDB.
Note: It is up to the caller to manage theClientSession
lifecycle. UseReactiveSessionScoped.execute(ReactiveSessionCallback, Consumer)
to provide a hook for processing theClientSession
when done.- Parameters:
sessionProvider
- must not be null.- Returns:
- new instance of
ReactiveSessionScoped
. Never null. - Since:
- 2.1
-
withSession
Obtain aClientSession
bound instance ofReactiveMongoOperations
.
Note: It is up to the caller to manage theClientSession
lifecycle.- Returns:
ClientSession
bound instance ofReactiveMongoOperations
.- 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.
-
createView
default reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, Class<?> source, AggregationOperation... stages) Create a view with the provided name. The view content is defined by thepipeline stages
on another collection or view identified by the givensource type
.- Parameters:
name
- the name of the view to create.source
- the type defining the views source collection.stages
- theaggregation pipeline stages
defining the view content.- Since:
- 4.0
-
createView
default reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, Class<?> source, AggregationPipeline pipeline) Create a view with the provided name. The view content is defined by thepipeline
on another collection or view identified by the givensource type
.- Parameters:
name
- the name of the view to create.source
- the type defining the views source collection.pipeline
- theAggregationPipeline
defining the view content.- Since:
- 4.0
-
createView
reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, Class<?> source, AggregationPipeline pipeline, @Nullable ViewOptions options) Create a view with the provided name. The view content is defined by thepipeline
on another collection or view identified by the givensource type
.- Parameters:
name
- the name of the view to create.source
- the type defining the views source collection.pipeline
- theAggregationPipeline
defining the view content.options
- additional settings to apply when creating the view. Can be null.- Since:
- 4.0
-
createView
reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> createView(String name, String source, AggregationPipeline pipeline, @Nullable ViewOptions options) Create a view with the provided name. The view content is defined by thepipeline
on another collection or view identified by the given source.- 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
- theAggregationPipeline
defining the view content.options
- additional settings to apply when creating the view. Can be null.- Since:
- 4.0
-
getCollectionNames
reactor.core.publisher.Flux<String> getCollectionNames()A set of collection names.- Returns:
- Flux of collection names.
-
getCollection
reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document>> getCollection(String collectionName) Get aMongoCollection
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 viacreateCollection(Class)
. Please make sure to check if the collectionexists
first.
Translate any exceptions as necessary.- Parameters:
collectionName
- name of the collection.- Returns:
- an existing collection or one created on first server interaction.
-
collectionExists
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
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
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
Drop the collection with the given name.
Translate any exceptions as necessary.- Parameters:
collectionName
- name of the collection to drop/delete.
-
bulkOps
Returns a newReactiveBulkOperations
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. UsebulkOps(BulkMode, Class, String)
to get full type specific support.- Parameters:
mode
- theBulkOperations.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- Since:
- 4.1
-
bulkOps
Returns a newReactiveBulkOperations
for the given entity type.- Parameters:
mode
- theBulkOperations.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.- Since:
- 4.1
-
bulkOps
ReactiveBulkOperations bulkOps(BulkOperations.BulkMode mode, @Nullable Class<?> entityType, String collectionName) Returns a newReactiveBulkOperations
for the given entity type and collection name.- Parameters:
mode
- theBulkOperations.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.- Since:
- 4.1
-
findAll
Query for aFlux
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 ofMappingMongoConverter
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 returnedFlux
.- Returns:
- the converted collection.
-
findAll
Query for aFlux
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 ofMappingMongoConverter
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 returnedFlux
.collectionName
- name of the collection to retrieve the objects from.- Returns:
- the converted collection.
-
findOne
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 ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass
- the parametrized type of the returnedMono
.- Returns:
- the converted object.
-
findOne
<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 . Unless configured otherwise, an instance ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass
- the parametrized type of the returnedMono
.collectionName
- name of the collection to retrieve the objects from.- Returns:
- the converted object.
-
exists
Determine result of givenQuery
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. Useexists(Query, Class, String)
to get full type specific support.- Parameters:
query
- theQuery
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
Determine result of givenQuery
contains at least one element.- Parameters:
query
- theQuery
class that specifies the criteria used to find a document.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 givenQuery
contains at least one element.- Parameters:
query
- theQuery
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
Map the results of an ad-hoc query on the collection for the entity class to aFlux
of the specified type.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification. Must not be null.entityClass
- the parametrized type of the returnedFlux
. Must not be null.- Returns:
- the
Flux
of converted objects.
-
find
Map the results of an ad-hoc query on the specified collection to aFlux
of the specified type.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification. Must not be null.entityClass
- the parametrized type of the returnedFlux
.collectionName
- name of the collection to retrieve the objects from. Must not be null.- Returns:
- the
Flux
of converted objects.
-
scroll
Query for a scroll of objects of type T from the specified collection.
Make sure to either setQuery.skip(long)
orQuery.with(KeysetScrollPosition)
along withQuery.limit(int)
to limit large query results for efficient scrolling.
Result objects are converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverter
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-nullablesort properties
as MongoDB does not support criteria to reconstruct a query result from absent document fields ornull
values through$gt/$lt
operators.- 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.- Throws:
IllegalStateException
- if a potentialKeysetScrollPosition
contains an invalid position.- Since:
- 4.1
- See Also:
-
scroll
<T> reactor.core.publisher.Mono<Window<T>> scroll(Query query, Class<T> entityType, String collectionName) Query for a window of objects of type T from the specified collection.
Make sure to either setQuery.skip(long)
orQuery.with(KeysetScrollPosition)
along withQuery.limit(int)
to limit large query results for efficient scrolling.
Result objects are converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverter
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-nullablesort properties
as MongoDB does not support criteria to reconstruct a query result from absent document fields ornull
values through$gt/$lt
operators.- 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.- Throws:
IllegalStateException
- if a potentialKeysetScrollPosition
contains an invalid position.- Since:
- 4.1
- See Also:
-
findById
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
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 singleMongoCollection
or view and returns the results in aFlux
.- Parameters:
field
- the name of the field to inspect for distinct values. Must not be null.entityClass
- the domain type used for determining the actualMongoCollection
. 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 singleMongoCollection
or view and returns the results in aFlux
.- Parameters:
query
- filterQuery
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 actualMongoCollection
and mapping theQuery
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 singleMongoCollection
or view and returns the results in aFlux
.- Parameters:
query
- filterQuery
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 actualMongoCollection
. Must not be null.entityClass
- the domain type used for mapping theQuery
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 singleMongoCollection
or view and returns the results in aFlux
.- Parameters:
query
- filterQuery
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 actualMongoCollection
. 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 withAggregationOptions.getCursorBatchSize()
. Enabling explanation mode or setting batch size causeIllegalArgumentException
.- Parameters:
aggregation
- TheTypedAggregation
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 returnedFlux
. Must not be null.- Returns:
- The results of the aggregation operation.
- Throws:
IllegalArgumentException
- ifaggregation
,collectionName
oroutputType
is null.
-
aggregate
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 theaggregation input type
.
Aggregation streaming cannot be used withaggregation explain
nor withAggregationOptions.getCursorBatchSize()
. Enabling explanation mode or setting batch size causeIllegalArgumentException
.- Parameters:
aggregation
- TheTypedAggregation
specification holding the aggregation operations. Must not be null.outputType
- The parametrized type of the returnedFlux
. Must not be null.- Returns:
- The results of the aggregation operation.
- Throws:
IllegalArgumentException
- ifaggregation
oroutputType
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 givenouputType
. The name of the inputCollection is derived from theinputType
.
Aggregation streaming cannot be used withaggregation explain
nor withAggregationOptions.getCursorBatchSize()
. Enabling explanation mode or setting batch size causeIllegalArgumentException
.- Parameters:
aggregation
- TheAggregation
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 returnedFlux
. Must not be null.- Returns:
- The results of the aggregation operation.
- Throws:
IllegalArgumentException
- ifaggregation
,inputType
oroutputType
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 withaggregation explain
nor withAggregationOptions.getCursorBatchSize()
. Enabling explanation mode or setting batch size causeIllegalArgumentException
.- Parameters:
aggregation
- TheAggregation
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 returnedFlux
. Must not be null.- Returns:
- The results of the aggregation operation.
- Throws:
IllegalArgumentException
- ifaggregation
,collectionName
oroutputType
is null.
-
geoNear
@Deprecated <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near, Class<T> entityClass) Deprecated.since 2.2. Theeval
command has been removed in MongoDB Server 4.2.0. Use Aggregations withAggregation.geoNear(NearQuery, String)
instead.ReturnsFlux
ofGeoResult
for all entities matching the givenNearQuery
. Will consider entity mapping information to determine the collection the query is ran against. Note, that MongoDB limits the number of results by default. Make sure to add an explicit limit to theNearQuery
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 emulategeoNear
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);
- Parameters:
near
- must not be null.entityClass
- must not be null.- Returns:
- the converted
GeoResult
s.
-
geoNear
@Deprecated <T> reactor.core.publisher.Flux<GeoResult<T>> geoNear(NearQuery near, Class<T> entityClass, String collectionName) Deprecated.since 2.2. Theeval
command has been removed in MongoDB Server 4.2.0. Use Aggregations withAggregation.geoNear(NearQuery, String)
instead.ReturnsFlux
ofGeoResult
for all entities matching the givenNearQuery
. Note, that MongoDB limits the number of results by default. Make sure to add an explicit limit to theNearQuery
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 emulategeoNear
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);
- 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
GeoResult
s.
-
findAndModify
<T> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, Class<T> entityClass) Triggers findAndModify to apply providedUpdate
on documents matchingCriteria
of givenQuery
.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.update
- theUpdateDefinition
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.
- Since:
- 3.0
- See Also:
-
findAndModify
<T> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, Class<T> entityClass, String collectionName) Triggers findAndModify to apply providedUpdate
on documents matchingCriteria
of givenQuery
.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.update
- theUpdateDefinition
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.
- Since:
- 3.0
- See Also:
-
findAndModify
<T> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass) Triggers findAndModify to apply providedUpdate
on documents matchingCriteria
of givenQuery
takingFindAndModifyOptions
into account.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification.update
- theUpdateDefinition
to apply on matching documents.options
- theFindAndModifyOptions
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. - Since:
- 3.0
- See Also:
-
findAndModify
<T> reactor.core.publisher.Mono<T> findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass, String collectionName) Triggers findAndModify to apply providedUpdate
on documents matchingCriteria
of givenQuery
takingFindAndModifyOptions
into account.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.update
- theUpdateDefinition
to apply on matching documents. Must not be null.options
- theFindAndModifyOptions
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. - Since:
- 3.0
- See Also:
-
findAndReplace
Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document.
Options are defaulted toFindAndReplaceOptions.empty()
.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document 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. - Throws:
MappingException
- if the collection name cannot bederived
from the given replacement value.- 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 matchingCriteria
of givenQuery
with thereplacement
document.
Options are defaulted toFindAndReplaceOptions.empty()
.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document 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) Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.replacement
- the replacement document. Must not be null.options
- theFindAndModifyOptions
holding additional information. Must not be null.- Returns:
- the converted object that was updated or
Mono.empty()
, if not found. Depending on the value ofFindAndReplaceOptions.isReturnNew()
this will either be the object as it was before the update or as it is after the update. - Throws:
MappingException
- if the collection name cannot bederived
from the given replacement value.- Since:
- 2.1
-
findAndReplace
default <T> reactor.core.publisher.Mono<T> findAndReplace(Query query, T replacement, FindAndReplaceOptions options, String collectionName) Triggers findOneAndReplace to replace a single document matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.replacement
- the replacement document. Must not be null.options
- theFindAndModifyOptions
holding additional information. Must not be null.- Returns:
- the converted object that was updated or
Mono.empty()
, if not found. Depending on the value ofFindAndReplaceOptions.isReturnNew()
this will either be the object as it was before the update or as it is after the update. - 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 matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.replacement
- the replacement document. Must not be null.options
- theFindAndModifyOptions
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 ofFindAndReplaceOptions.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 matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.replacement
- the replacement document. Must not be null.options
- theFindAndModifyOptions
holding additional information. Must not be null.entityType
- the type used for mapping theQuery
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 ofObject.class
instead.- Returns:
- the converted object that was updated or
Mono.empty()
, if not found. Depending on the value ofFindAndReplaceOptions.isReturnNew()
this will either be the object as it was before the update or as it is after the update. - Throws:
MappingException
- if the collection name cannot bederived
from the given replacement value.- 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 matchingCriteria
of givenQuery
with thereplacement
document takingFindAndReplaceOptions
into account.
NOTE: The replacement entity must not hold an id.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document and also an optional fields specification. Must not be null.replacement
- the replacement document. Must not be null.options
- theFindAndModifyOptions
holding additional information. Must not be null.entityType
- the type used for mapping theQuery
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 ofObject.class
instead.- Returns:
- the converted object that was updated or
Mono.empty()
, if not found. Depending on the value ofFindAndReplaceOptions.isReturnNew()
this will either be the object as it was before the update or as it is after the update. - Since:
- 2.1
-
findAndRemove
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 aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass
- the parametrized type of the returnedMono
.- Returns:
- the converted object
-
findAndRemove
<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 . Unless configured otherwise, an instance ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass
- the parametrized type of the returnedMono
.collectionName
- name of the collection to retrieve the objects from.- Returns:
- the converted object.
-
count
Returns the number of documents for the givenQuery
by querying the collection of the given entity class.
NOTE: Queryoffset
andlimit
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 useestimatedCount(Class)
for empty queries instead of running anaggregation execution
which may have an impact on performance.- Parameters:
query
- theQuery
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.
- Throws:
MappingException
- if the collection name cannot bederived
from the given type.- See Also:
-
count
Returns the number of documents for the givenQuery
querying the given collection. The givenQuery
must solely consist of document field references as we lack type information to map potential property references onto document fields. Usecount(Query, Class, String)
to get full type specific support.
NOTE: Queryoffset
andlimit
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 useestimatedCount(Class)
for empty queries instead of running anaggregation execution
which may have an impact on performance.- Parameters:
query
- theQuery
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
reactor.core.publisher.Mono<Long> count(Query query, @Nullable Class<?> entityClass, String collectionName) Returns the number of documents for the givenQuery
by querying the given collection using the given entity class to map the givenQuery
.
NOTE: Queryoffset
andlimit
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 useestimatedCount(Class)
for empty queries instead of running anaggregation execution
which may have an impact on performance.- Parameters:
query
- theQuery
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:
-
estimatedCount
Estimate the number of documents, in the collectionidentified by the given type
, based on collection statistics.
Please make sure to read the MongoDB reference documentation about limitations on eg. sharded cluster or inside transactions.- Parameters:
entityClass
- must not be null.- Returns:
- a
Mono
emitting the estimated number of documents. - Throws:
MappingException
- if the collection name cannot bederived
from the given type.- Since:
- 3.1
-
estimatedCount
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.- Parameters:
collectionName
- must not be null.- Returns:
- a
Mono
emitting the estimated number of documents. - Since:
- 3.1
-
exactCount
Returns the number of documents for the givenQuery
by querying the collection of the given entity class.
NOTE: Queryoffset
andlimit
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 anaggregation execution
even for emptyqueries
which may have an impact on performance, but guarantees shard, session and transaction compliance. In case an inaccurate count satisfies the applications needs useestimatedCount(Class)
for empty queries instead.- Parameters:
query
- theQuery
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.
- Throws:
MappingException
- if the collection name cannot bederived
from the given type.- Since:
- 3.4
-
exactCount
Returns the number of documents for the givenQuery
querying the given collection. The givenQuery
must solely consist of document field references as we lack type information to map potential property references onto document fields. Usecount(Query, Class, String)
to get full type specific support.
NOTE: Queryoffset
andlimit
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 anaggregation execution
even for emptyqueries
which may have an impact on performance, but guarantees shard, session and transaction compliance. In case an inaccurate count satisfies the applications needs useestimatedCount(String)
for empty queries instead.- Parameters:
query
- theQuery
class that specifies the criteria used to find documents.collectionName
- must not be null or empty.- Returns:
- the count of matching documents.
- Since:
- 3.4
- See Also:
-
exactCount
reactor.core.publisher.Mono<Long> exactCount(Query query, @Nullable Class<?> entityClass, String collectionName) Returns the number of documents for the givenQuery
by querying the given collection using the given entity class to map the givenQuery
.
NOTE: Queryoffset
andlimit
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 anaggregation execution
even for emptyqueries
which may have an impact on performance, but guarantees shard, session and transaction compliance. In case an inaccurate count satisfies the applications needs useestimatedCount(String)
for empty queries instead.- Parameters:
query
- theQuery
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.
- Since:
- 3.4
-
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 .
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.- Parameters:
objectToSave
- the object to store in the collection. Must not be null.- Returns:
- the inserted object.
- Throws:
IllegalArgumentException
- in case theobjectToSave
is collection-like.MappingException
- if the target collection name cannot bederived
from the given object type.
-
insert
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 ofMappingMongoConverter
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.- 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.
- Throws:
IllegalArgumentException
- in case theobjectToSave
is collection-like.
-
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.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.- 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.
- Throws:
MappingException
- if the target collection name cannot bederived
from the given type.
-
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.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.- 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
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.- Parameters:
objectsToSave
- the list of objects to save. Must not be null.- Returns:
- the saved objects.
- Throws:
MappingException
- if the target collection name cannot bederived
for the given 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 .
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.- 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.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.- 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.
- Throws:
MappingException
- if the target collection name cannot bederived
for the type.
-
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.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.- 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.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.- 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 . Unless configured otherwise, an instance ofMappingMongoConverter
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.- Parameters:
objectToSave
- the object to store in the collection. Must not be null.- Returns:
- the saved object.
- Throws:
IllegalArgumentException
- in case theobjectToSave
is collection-like.MappingException
- if the target collection name cannot bederived
from the given object type.OptimisticLockingFailureException
- in case of version mismatch in case aVersion
is defined.
-
save
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 ofMappingMongoConverter
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.- 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.
- Throws:
IllegalArgumentException
- in case theobjectToSave
is collection-like.OptimisticLockingFailureException
- in case of version mismatch in case aVersion
is defined.
-
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 . Unless configured otherwise, an instance ofMappingMongoConverter
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.- Parameters:
objectToSave
- the object to store in the collection. Must not be null.- Returns:
- the saved object.
- Throws:
MappingException
- if the target collection name cannot bederived
from the given object type.OptimisticLockingFailureException
- in case of version mismatch in case aVersion
is defined.
-
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 . Unless configured otherwise, an instance ofMappingMongoConverter
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.- 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.
- Throws:
OptimisticLockingFailureException
- in case of version mismatch in case aVersion
is defined.
-
upsert
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition 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.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.NOTE:
sorting
is not supported bydb.collection.updateOne
. UsefindAndModify(Query, UpdateDefinition, Class)
instead.- Parameters:
query
- the query document that specifies the criteria used to select a document to be upserted. Must not be null.update
- theUpdateDefinition
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. - Throws:
MappingException
- if the target collection name cannot bederived
from the given type.- Since:
- 3.0
- See Also:
-
upsert
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition 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. Useupsert(Query, UpdateDefinition, Class, String)
to get full type specific support.- Parameters:
query
- the query document that specifies the criteria used to select a document to be upserted. Must not be null.update
- theUpdateDefinition
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. - Since:
- 3.0
- See Also:
-
upsert
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> upsert(Query query, UpdateDefinition 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.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- the query document that specifies the criteria used to select a document to be upserted. Must not be null.update
- theUpdateDefinition
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. - Since:
- 3.0
- See Also:
-
updateFirst
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, Class<?> entityClass) Updates the first object that is found in the collection of the entity class that matches the query document with the provided update document.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update. NOTE:sorting
is not supported bydb.collection.updateOne
. UsefindAndModify(Query, UpdateDefinition, Class)
instead.- Parameters:
query
- the query document that specifies the criteria used to select a document to be updated. Must not be null.update
- theUpdateDefinition
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. - Throws:
MappingException
- if the target collection name cannot bederived
from the given type.- Since:
- 3.0
- See Also:
-
updateFirst
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, String collectionName) Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.
NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of domain type information. UseupdateFirst(Query, UpdateDefinition, Class, String)
to get full type specific support.
NOTE:sorting
is not supported bydb.collection.updateOne
. UsefindAndModify(Query, UpdateDefinition, Class, String)
instead.- Parameters:
query
- the query document that specifies the criteria used to select a document to be updated. Must not be null.update
- theUpdateDefinition
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. - Since:
- 3.0
- See Also:
-
updateFirst
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateFirst(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- the query document that specifies the criteria used to select a document to be updated. Must not be null.update
- theUpdateDefinition
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. - Since:
- 3.0
- See Also:
-
updateMulti
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, Class<?> entityClass) Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- the query document that specifies the criteria used to select a document to be updated. Must not be null.update
- theUpdateDefinition
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. - Throws:
MappingException
- if the target collection name cannot bederived
from the given type.- Since:
- 3.0
- See Also:
-
updateMulti
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, String collectionName) Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document.
NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of domain type information. UseupdateMulti(Query, UpdateDefinition, Class, String)
to get full type specific support.- Parameters:
query
- the query document that specifies the criteria used to select a document to be updated. Must not be null.update
- theUpdateDefinition
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. - Since:
- 3.0
- See Also:
-
updateMulti
reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> updateMulti(Query query, UpdateDefinition update, Class<?> entityClass, String collectionName) Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document.A potential
Version
property of the entityClass will be auto-incremented if not explicitly specified in the update.- Parameters:
query
- the query document that specifies the criteria used to select a document to be updated. Must not be null.update
- theUpdateDefinition
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. - Since:
- 3.0
- See Also:
-
remove
Remove the given object from the collection by id and (if applicable) itsVersion
.- Parameters:
object
- must not be null.- Returns:
- the
DeleteResult
which lets you access the results of the previous delete. - Throws:
MappingException
- if the target collection name cannot bederived
from the given object type.
-
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 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
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 and (if applicable) itsVersion
.- Parameters:
objectToRemove
- must not be null.- Returns:
- the
DeleteResult
which lets you access the results of the previous delete. - Throws:
MappingException
- if the target collection name cannot bederived
from the given object type.
-
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 by id and (if applicable) itsVersion
.- 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
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 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 document.entityClass
- class that determines the collection to use.- Returns:
- the
DeleteResult
which lets you access the results of the previous delete. - Throws:
MappingException
- if the target collection name cannot bederived
from the given type.
-
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 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 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.
-
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. Useremove(Query, Class, String)
to get full type specific support.- 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.
-
findAllAndRemove
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. UsefindAllAndRemove(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 documents will be removed from, must not be null or empty.- Returns:
- the
Flux
converted objects deleted by this operation.
-
findAllAndRemove
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. - Throws:
MappingException
- if the target collection name cannot bederived
from the given type.
-
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 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 documents will be removed from, must not be null or empty.- Returns:
- the
Flux
converted objects deleted by this operation.
-
replace
default <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> replace(Query query, T replacement) Replace a single document matching theCriteria
of givenQuery
with thereplacement
document.
The collection name is derived from the replacement type.
Options are defaulted toReplaceOptions.none()
.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document. The query may contain an indexhint
or thecollation
to use. Must not be null.replacement
- the replacement document. Must not be null.- Returns:
- the
UpdateResult
which lets you access the results of the previous replacement. - Throws:
MappingException
- if the collection name cannot bederived
from the given replacement value.- Since:
- 4.2
-
replace
default <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> replace(Query query, T replacement, String collectionName) Replace a single document matching theCriteria
of givenQuery
with thereplacement
document. Options are defaulted toReplaceOptions.none()
.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document. The query may contain an indexhint
or thecollation
to use. Must not be null.replacement
- the replacement document. Must not be null.collectionName
- the collection to query. Must not be null.- Returns:
- the
UpdateResult
which lets you access the results of the previous replacement. - Since:
- 4.2
-
replace
default <T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> replace(Query query, T replacement, ReplaceOptions options) Replace a single document matching theCriteria
of givenQuery
with thereplacement
document takingReplaceOptions
into account.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document.The query may contain an indexhint
or thecollation
to use. Must not be null.replacement
- the replacement document. Must not be null.options
- theReplaceOptions
holding additional information. Must not be null.- Returns:
- the
UpdateResult
which lets you access the results of the previous replacement. - Throws:
MappingException
- if the collection name cannot bederived
from the given replacement value.- Since:
- 4.2
-
replace
<T> reactor.core.publisher.Mono<com.mongodb.client.result.UpdateResult> replace(Query query, T replacement, ReplaceOptions options, String collectionName) Replace a single document matching theCriteria
of givenQuery
with thereplacement
document takingReplaceOptions
into account.- Parameters:
query
- theQuery
class that specifies theCriteria
used to find a document. The query may * contain an indexhint
or thecollation
to use. Must not be null.replacement
- the replacement document. Must not be null.options
- theReplaceOptions
holding additional information. Must not be null.- Returns:
- the
UpdateResult
which lets you access the results of the previous replacement. - Throws:
MappingException
- if the collection name cannot bederived
from the given replacement value.- Since:
- 4.2
-
tail
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 atailable
cursor that may be an infinite stream. The stream will not be completed unless theSubscription
iscanceled
.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass
- the parametrized type of the returnedFlux
.- Returns:
- the
Flux
of converted objects. - Throws:
MappingException
- if the target collection name cannot bederived
from the given type.
-
tail
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 atailable
cursor that may be an infinite stream. The stream will not be completed unless theSubscription
iscanceled
.
The object is converted from the MongoDB native representation using an instance of . Unless configured otherwise, an instance ofMappingMongoConverter
will be used.
The query is specified as aQuery
which can be created either using theBasicQuery
or the more feature richQuery
.- Parameters:
query
- the query class that specifies the criteria used to find a document and also an optional fields specification.entityClass
- the parametrized type of the returnedFlux
.collectionName
- name of the collection to retrieve the objects from.- Returns:
- the
Flux
of converted objects.
-
changeStream
default <T> reactor.core.publisher.Flux<ChangeStreamEvent<T>> changeStream(ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream for all events in the configured default database via the reactive infrastructure. Use the optional providedAggregation
to filter events. The stream will not be completed unless theSubscription
iscanceled
.
TheChangeStreamEvent.getBody()
is mapped to the resultType while theChangeStreamEvent.getRaw()
contains the unmodified payload.
UseChangeStreamOptions
to set arguments likethe resumseToken
for resuming change streams.- Type Parameters:
T
-- Parameters:
options
- must not be null. UseChangeStreamOptions.empty()
.targetType
- the result type to use.- Returns:
- the
Flux
emittingevents
as they arrive. - Since:
- 2.1
- See Also:
-
changeStream
default <T> reactor.core.publisher.Flux<ChangeStreamEvent<T>> changeStream(@Nullable String collectionName, ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream for all events in the given collection via the reactive infrastructure. Use the optional providedAggregation
to filter events. The stream will not be completed unless theSubscription
iscanceled
.
TheChangeStreamEvent.getBody()
is mapped to the resultType while theChangeStreamEvent.getRaw()
contains the unmodified payload.
UseChangeStreamOptions
to set arguments likethe resumseToken
for resuming change streams.- Type Parameters:
T
-- Parameters:
collectionName
- the collection to watch. Can be null to watch all collections.options
- must not be null. UseChangeStreamOptions.empty()
.targetType
- the result type to use.- Returns:
- the
Flux
emittingevents
as they arrive. - Since:
- 2.1
- See Also:
-
changeStream
<T> reactor.core.publisher.Flux<ChangeStreamEvent<T>> changeStream(@Nullable String database, @Nullable String collectionName, ChangeStreamOptions options, Class<T> targetType) Subscribe to a MongoDB Change Stream via the reactive infrastructure. Use the optional providedAggregation
to filter events. The stream will not be completed unless theSubscription
iscanceled
.
TheChangeStreamEvent.getBody()
is mapped to the resultType while theChangeStreamEvent.getRaw()
contains the unmodified payload.
UseChangeStreamOptions
to set arguments likethe resumseToken
for resuming change streams.- Type Parameters:
T
-- Parameters:
database
- the database to watch. Can be null, uses configured default if so.collectionName
- the collection to watch. Can be null, watches all collections if so.options
- must not be null. UseChangeStreamOptions.empty()
.targetType
- the result type to use.- Returns:
- the
Flux
emittingevents
as they arrive. - Since:
- 2.1
- See Also:
-
mapReduce
@Deprecated <T> reactor.core.publisher.Flux<T> mapReduce(Query filterQuery, Class<?> domainType, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Deprecated.since 3.4 in favor ofaggregate(TypedAggregation, Class)
.Execute a map-reduce operation. UseMapReduceOptions
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 filterQuery
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
@Deprecated <T> reactor.core.publisher.Flux<T> mapReduce(Query filterQuery, Class<?> domainType, String inputCollectionName, Class<T> resultType, String mapFunction, String reduceFunction, MapReduceOptions options) Deprecated.since 3.4 in favor ofaggregate(TypedAggregation, Class)
.Execute a map-reduce operation. UseMapReduceOptions
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 filterQuery
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
-
getConverter
MongoConverter getConverter()Returns the underlyingMongoConverter
.- Returns:
- never null.
-
getCollectionName
The collection name used for the specified class by this template.- Parameters:
entityClass
- must not be null.- Returns:
- never null.
- Throws:
MappingException
- if the collection name cannot be derived from the type.- Since:
- 2.1
-