org.springframework.data.mongodb.core

Interface BulkOperations



  • public interface BulkOperations
    Bulk operations for insert/update/remove actions on a collection. These bulks operation 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().
    Since:
    1.9
    Author:
    Tobias Trelle, Oliver Gierke
    • Method Detail

      • insert

        BulkOperations insert(Object documents)
        Add a single insert to the bulk operation.
        Parameters:
        documents - the document to insert, must not be null.
        Returns:
        the current BulkOperations instance with the insert added, will never be null.
      • insert

        BulkOperations insert(List<? extends Object> documents)
        Add a list of inserts to the bulk operation.
        Parameters:
        documents - List of documents to insert, must not be null.
        Returns:
        the current BulkOperations instance with the insert added, will never be null.
      • updateOne

        BulkOperations updateOne(Query query,
                                 Update update)
        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 - Update operation to perform, must not be null.
        Returns:
        the current BulkOperations instance with the update added, will never be null.
      • updateOne

        BulkOperations updateOne(List<Pair<Query,Update>> updates)
        Add a list of updates to the bulk operation. For each update request, only the first matching document is updated.
        Parameters:
        updates - Update operations to perform.
        Returns:
        the current BulkOperations instance with the update added, will never be null.
      • updateMulti

        BulkOperations updateMulti(Query query,
                                   Update update)
        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 BulkOperations instance with the update added, will never be null.
      • updateMulti

        BulkOperations updateMulti(List<Pair<Query,Update>> updates)
        Add a list of updates to the bulk operation. For each update request, all matching documents are updated.
        Parameters:
        updates - Update operations to perform.
        Returns:
        The bulk operation.
      • upsert

        BulkOperations upsert(Query query,
                              Update update)
        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 bulk operation.
      • upsert

        BulkOperations upsert(List<Pair<Query,Update>> updates)
        Add a list of upserts to the bulk operation. An upsert is an update if the set of matching documents is not empty, else an insert.
        Parameters:
        updates - Updates/insert operations to perform.
        Returns:
        The bulk operation.
      • remove

        BulkOperations remove(Query remove)
        Add a single remove operation to the bulk operation.
        Parameters:
        remove - the Query to select the documents to be removed, must not be null.
        Returns:
        the current BulkOperations instance with the removal added, will never be null.
      • remove

        BulkOperations remove(List<Query> removes)
        Add a list of remove operations to the bulk operation.
        Parameters:
        removes - the remove operations to perform, must not be null.
        Returns:
        the current BulkOperations instance with the removal added, will never be null.
      • execute

        com.mongodb.bulk.BulkWriteResult execute()
        Execute all bulk operations using the default write concern.
        Returns:
        Result of the bulk operation providing counters for inserts/updates etc.
        Throws:
        BulkOperationException - if an error occurred during bulk processing.