Interface ReactiveBulkOperations
public interface ReactiveBulkOperations
Bulk operations for insert/update/remove actions on a collection. Bulk operations are available since MongoDB 2.6 and
make use of low level bulk commands on the protocol level. This interface defines a fluent API to add multiple single
operations or list of similar operations in sequence which can then eventually be executed by calling
execute()
.
ReactiveMongoOperations ops = …; ops.bulkOps(BulkMode.UNORDERED, Person.class) .insert(newPerson) .updateOne(where("firstname").is("Joe"), Update.update("lastname", "Doe")) .execute();
Bulk operations are issued as one batch that pulls together all insert, update, and delete operations. Operations
that require individual operation results such as optimistic locking (using @Version
) are not supported and
the version field remains not populated.
- Since:
- 4.1
- Author:
- Christoph Strobl
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<com.mongodb.bulk.BulkWriteResult>
execute()
Execute all bulk operations using the default write concern.Add a single insert to the bulk operation.Add a list of inserts to the bulk operation.Add a list of remove operations to the bulk operation.Add a single remove operation to the bulk operation.default ReactiveBulkOperations
replaceOne
(Query query, Object replacement) Add a single replace operation to the bulk operation.replaceOne
(Query query, Object replacement, FindAndReplaceOptions options) Add a single replace operation to the bulk operation.updateMulti
(Query query, UpdateDefinition update) Add a single update to the bulk operation.updateOne
(Query query, UpdateDefinition update) Add a single update to the bulk operation.upsert
(Query query, UpdateDefinition update) Add a single upsert to the bulk operation.
-
Method Details
-
insert
Add a single insert to the bulk operation.- Parameters:
documents
- the document to insert, must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the insert added, will never be null.
-
insert
Add a list of inserts to the bulk operation.- Parameters:
documents
- List of documents to insert, must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the insert added, will never be null.
-
updateOne
Add a single update to the bulk operation. For the update request, only the first matching document is updated.- Parameters:
query
- update criteria, must not be null.update
-UpdateDefinition
operation to perform, must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the update added, will never be null.
-
updateMulti
Add a single update to the bulk operation. For the update request, all matching documents are updated.- Parameters:
query
- Update criteria.update
- Update operation to perform.- Returns:
- the current
ReactiveBulkOperations
instance with the update added, will never be null.
-
upsert
Add a single upsert to the bulk operation. An upsert is an update if the set of matching documents is not empty, else an insert.- Parameters:
query
- Update criteria.update
- Update operation to perform.- Returns:
- the current
ReactiveBulkOperations
instance with the update added, will never be null.
-
remove
Add a single remove operation to the bulk operation.- Parameters:
remove
- theQuery
to select the documents to be removed, must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the removal added, will never be null.
-
remove
Add a list of remove operations to the bulk operation.- Parameters:
removes
- the remove operations to perform, must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the removal added, will never be null.
-
replaceOne
Add a single replace operation to the bulk operation.- Parameters:
query
- Update criteria.replacement
- the replacement document. Must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the replace added, will never be null.
-
replaceOne
Add a single replace operation to the bulk operation.- Parameters:
query
- Update criteria.replacement
- the replacement document. Must not be null.options
- theFindAndModifyOptions
holding additional information. Must not be null.- Returns:
- the current
ReactiveBulkOperations
instance with the replace added, will never be null.
-
execute
reactor.core.publisher.Mono<com.mongodb.bulk.BulkWriteResult> execute()Execute all bulk operations using the default write concern.- Returns:
- a
Mono
emitting the result of the bulk operation providing counters for inserts/updates etc.
-