Class ChangeStreamDocument<TDocument>

  • Type Parameters:
    TDocument - The type that this collection will encode the fullDocument field into.


    public final class ChangeStreamDocument<TDocument>
    extends Object
    Represents the $changeStream aggregation output document.

    Note: this class will not be applicable for all change stream outputs. If using custom pipelines that radically change the change stream result, then an alternative document format should be used.

    Since:
    3.6
    • Constructor Detail

      • ChangeStreamDocument

        @Deprecated
        public ChangeStreamDocument​(org.bson.BsonDocument resumeToken,
                                    MongoNamespace namespace,
                                    TDocument fullDocument,
                                    org.bson.BsonDocument documentKey,
                                    @Nullable
                                    org.bson.BsonTimestamp clusterTime,
                                    OperationType operationType,
                                    UpdateDescription updateDescription)
        Deprecated. 
        Creates a new instance
        Parameters:
        resumeToken - the resume token
        namespace - the namespace
        documentKey - a document containing the _id of the changed document
        clusterTime - the cluster time at which the change occurred
        fullDocument - the fullDocument
        operationType - the operation type
        updateDescription - the update description
      • ChangeStreamDocument

        public ChangeStreamDocument​(@BsonProperty("resumeToken")
                                    org.bson.BsonDocument resumeToken,
                                    @BsonProperty("ns")
                                    org.bson.BsonDocument namespaceDocument,
                                    @BsonProperty("fullDocument")
                                    TDocument fullDocument,
                                    @BsonProperty("documentKey")
                                    org.bson.BsonDocument documentKey,
                                    @Nullable @BsonProperty("clusterTime")
                                    org.bson.BsonTimestamp clusterTime,
                                    @BsonProperty("operationType")
                                    OperationType operationType,
                                    @BsonProperty("updateDescription")
                                    UpdateDescription updateDescription)
        Creates a new instance
        Parameters:
        resumeToken - the resume token
        namespaceDocument - the BsonDocument representing the namespace
        fullDocument - the full document
        documentKey - a document containing the _id of the changed document
        clusterTime - the cluster time at which the change occured
        operationType - the operation type
        updateDescription - the update description
        Since:
        3.8
    • Method Detail

      • getResumeToken

        public org.bson.BsonDocument getResumeToken​()
        Returns the resumeToken
        Returns:
        the resumeToken
      • getNamespace

        @BsonIgnore
        @Nullable
        public MongoNamespace getNamespace​()
        Returns the namespace The invalidate operation type does include a MongoNamespace in the ChangeStreamDocument response. The dropDatabase operation type includes a MongoNamespace, but does not include a collection name as part of the namespace.
        Returns:
        the namespace. If the namespaceDocument is null or if it is missing either the 'db' or 'coll' keys, then this will return null.
      • getNamespaceDocument

        @BsonProperty("ns")
        public org.bson.BsonDocument getNamespaceDocument​()
        Returns the namespaceDocument The namespaceDocument is a BsonDocument containing the values associated with a MongoNamespace. The 'db' key refers to the database name and the 'coll' key refers to the collection name.
        Returns:
        the namespaceDocument
        Since:
        3.8
      • getDatabaseName

        @BsonIgnore
        @Nullable
        public String getDatabaseName​()
        Returns the database name
        Returns:
        the databaseName. If the namespaceDocument is null or if it is missing the 'db' key, then this will return null.
        Since:
        3.8
      • getFullDocument

        @Nullable
        public TDocument getFullDocument​()
        Returns the fullDocument
        Returns:
        the fullDocument
      • getDocumentKey

        public org.bson.BsonDocument getDocumentKey​()
        Returns a document containing just the _id of the changed document.

        For unsharded collections this contains a single field, _id, with the value of the _id of the document updated. For sharded collections, this will contain all the components of the shard key in order, followed by the _id if the _id isn’t part of the shard key.

        Returns:
        the document key
      • getClusterTime

        @Nullable
        public org.bson.BsonTimestamp getClusterTime​()
        Gets the cluster time at which the change occurred.
        Returns:
        the cluster time at which the change occurred
        Since:
        3.8
        Since server release
        4.0
      • getOperationType

        public OperationType getOperationType​()
        Returns the operationType
        Returns:
        the operationType
      • getUpdateDescription

        public UpdateDescription getUpdateDescription​()
        Returns the updateDescription
        Returns:
        the updateDescription
      • createCodec

        public static <TFullDocument> org.bson.codecs.Codec<ChangeStreamDocument<TFullDocument>> createCodec​(Class<TFullDocument> fullDocumentClass,
                                                                                                             org.bson.codecs.configuration.CodecRegistry codecRegistry)
        Creates the codec for the specific ChangeStreamOutput type
        Type Parameters:
        TFullDocument - the fullDocument type
        Parameters:
        fullDocumentClass - the class to use to represent the fullDocument
        codecRegistry - the codec registry
        Returns:
        the codec
      • hashCode

        public int hashCode​()
        Overrides:
        hashCode in class Object