Class BulkWriteResult



  • public abstract class BulkWriteResult
    extends Object
    The result of a successful bulk write operation.
    Since:
    3.0
    • Constructor Detail

      • BulkWriteResult

        public BulkWriteResult​()
    • Method Detail

      • wasAcknowledged

        public abstract boolean wasAcknowledged​()
        Returns true if the write was acknowledged.
        Returns:
        true if the write was acknowledged
        See Also:
        WriteConcern.UNACKNOWLEDGED
      • getInsertedCount

        public abstract int getInsertedCount​()
        Returns the number of documents inserted by the write operation.
        Returns:
        the number of documents inserted by the write operation
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
        See Also:
        WriteConcern.UNACKNOWLEDGED
      • getMatchedCount

        public abstract int getMatchedCount​()
        Returns the number of documents matched by updates or replacements in the write operation. This will include documents that matched the query but where the modification didn't result in any actual change to the document; for example, if you set the value of some field, and the field already has that value, that will still count as an update.
        Returns:
        the number of documents matched by updates in the write operation
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
        See Also:
        WriteConcern.UNACKNOWLEDGED
      • getDeletedCount

        public abstract int getDeletedCount​()
        Returns the number of documents deleted by the write operation.
        Returns:
        the number of documents deleted by the write operation
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
        See Also:
        WriteConcern.UNACKNOWLEDGED
      • isModifiedCountAvailable

        public abstract boolean isModifiedCountAvailable​()
        Returns true if the server was able to provide a count of modified documents. If this method returns false (which can happen if the server is not at least version 2.6) then the getModifiedCount method will throw UnsupportedOperationException.
        Returns:
        true if modifiedCount is available
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
        See Also:
        WriteConcern.UNACKNOWLEDGED, getModifiedCount()
      • getModifiedCount

        public abstract int getModifiedCount​()
        Returns the number of documents modified by the write operation. This only applies to updates or replacements, and will only count documents that were actually changed; for example, if you set the value of some field , and the field already has that value, that will not count as a modification.

        If the server is not able to provide a count of modified documents (which can happen if the server is not at least version 2.6), then this method will throw an UnsupportedOperationException

        Returns:
        the number of documents modified by the write operation
        Throws:
        UnsupportedOperationException - if the write was unacknowledged or if no modified count is available.
        See Also:
        WriteConcern.UNACKNOWLEDGED, isModifiedCountAvailable()
      • acknowledged

        public static BulkWriteResult acknowledged​(WriteRequest.Type type,
                                                   int count,
                                                   List<BulkWriteUpsert> upserts)
        Create an acknowledged BulkWriteResult
        Parameters:
        type - the type of the write
        count - the number of documents matched
        upserts - the list of upserts
        Returns:
        an acknowledged BulkWriteResult
      • acknowledged

        public static BulkWriteResult acknowledged​(WriteRequest.Type type,
                                                   int count,
                                                   Integer modifiedCount,
                                                   List<BulkWriteUpsert> upserts)
        Create an acknowledged BulkWriteResult
        Parameters:
        type - the type of the write
        count - the number of documents matched
        modifiedCount - the number of documents modified, which may be null if the server was not able to provide the count
        upserts - the list of upserts
        Returns:
        an acknowledged BulkWriteResult
      • acknowledged

        public static BulkWriteResult acknowledged​(int insertedCount,
                                                   int matchedCount,
                                                   int removedCount,
                                                   Integer modifiedCount,
                                                   List<BulkWriteUpsert> upserts)
        Create an acknowledged BulkWriteResult
        Parameters:
        insertedCount - the number of documents inserted by the write operation
        matchedCount - the number of documents matched by the write operation
        removedCount - the number of documents removed by the write operation
        modifiedCount - the number of documents modified, which may be null if the server was not able to provide the count
        upserts - the list of upserts
        Returns:
        an acknowledged BulkWriteResult
      • unacknowledged

        public static BulkWriteResult unacknowledged​()
        Create an unacknowledged BulkWriteResult
        Returns:
        an unacknowledged BulkWriteResult