Package com.mongodb

Class WriteConcernResult



  • public abstract class WriteConcernResult
    extends Object
    The result of a successful write operation. If the write was unacknowledged, then wasAcknowledged will return false and all other methods will throw MongoUnacknowledgedWriteException.
    Since:
    3.0
    See Also:
    WriteConcern.UNACKNOWLEDGED
    • Constructor Detail

      • WriteConcernResult

        public WriteConcernResult​()
    • Method Detail

      • wasAcknowledged

        public abstract boolean wasAcknowledged​()
        Returns true if the write was acknowledged.
        Returns:
        true if the write was acknowledged
      • getCount

        public abstract int getCount​()
        Returns the number of documents affected by the write operation.
        Returns:
        the number of documents affected by the write operation
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
      • isUpdateOfExisting

        public abstract boolean isUpdateOfExisting​()
        Returns true if the write was an update of an existing document.
        Returns:
        true if the write was an update of an existing document
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
      • getUpsertedId

        @Nullable
        public abstract BsonValue getUpsertedId​()
        Returns the value of _id if this write resulted in an upsert.
        Returns:
        the value of _id if this write resulted in an upsert.
        Throws:
        UnsupportedOperationException - if the write was unacknowledged.
      • acknowledged

        public static WriteConcernResult acknowledged​(int count,
                                                      boolean isUpdateOfExisting,
                                                      @Nullable
                                                      BsonValue upsertedId)
        Create an acknowledged WriteConcernResult
        Parameters:
        count - the count of matched documents
        isUpdateOfExisting - whether an existing document was updated
        upsertedId - if an upsert resulted in an inserted document, this is the _id of that document. This may be null
        Returns:
        an acknowledged WriteConcernResult
      • unacknowledged

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