Class UpdateDescription


  • public final class UpdateDescription
    extends Object
    Indicates which fields have been modified in a given update operation.
    • Constructor Detail

      • UpdateDescription

        public UpdateDescription​(BsonDocument updatedFields,
                                 Collection<String> removedFields)
        Creates an update description with the specified updated fields and removed field names.
        Parameters:
        updatedFields - Nested key-value pair representation of updated fields.
        removedFields - Collection of removed field names.
    • Method Detail

      • getUpdatedFields

        public BsonDocument getUpdatedFields()
        Returns a BsonDocument containing keys and values representing (respectively) the fields that have changed in the corresponding update and their new values.
        Returns:
        the updated field names and their new values.
      • getRemovedFields

        public Collection<String> getRemovedFields()
        Returns a List containing the field names that have been removed in the corresponding update.
        Returns:
        the removed fields names.
      • toUpdateDocument

        public BsonDocument toUpdateDocument()
        Convert this update description to an update document.
        Returns:
        an update document with the appropriate $set and $unset documents.
      • toBsonDocument

        public BsonDocument toBsonDocument()
        Converts this update description to its document representation as it would appear in a MongoDB Change Event.
        Returns:
        the update description document as it would appear in a change event
      • fromBsonDocument

        public static UpdateDescription fromBsonDocument​(BsonDocument document)
        Converts an update description BSON document from a MongoDB Change Event into an UpdateDescription object.
        Parameters:
        document - the
        Returns:
        the converted UpdateDescription
      • merge

        public UpdateDescription merge​(@Nullable
                                       UpdateDescription otherDescription)
        Unilaterally merge an update description into this update description.
        Parameters:
        otherDescription - the update description to merge into this
        Returns:
        this merged update description
      • diff

        public static UpdateDescription diff​(@Nullable
                                             BsonDocument beforeDocument,
                                             @Nullable
                                             BsonDocument afterDocument)
        Find the diff between two documents.

        NOTE: This does not do a full diff on [BsonArray]. If there is an inequality between the old and new array, the old array will simply be replaced by the new one.

        Parameters:
        beforeDocument - original document
        afterDocument - document to diff on
        Returns:
        a description of the updated fields and removed keys between the documents.
      • isEmpty

        public boolean isEmpty()
        Determines whether this update description is empty.
        Returns:
        true if the update description is empty, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object