Class ChangeStreamDocument<TDocument>

java.lang.Object
com.mongodb.client.model.changestream.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 Details

  • Method Details

    • getResumeToken

      public BsonDocument getResumeToken()
      Returns the resumeToken
      Returns:
      the resumeToken
    • getNamespace

      @BsonIgnore @Nullable public MongoNamespace getNamespace()
      Returns the namespace, derived from the "ns" field in a change stream document. 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") @Nullable public BsonDocument getNamespaceDocument()
      Returns the namespace document, derived from the "ns" field in a change stream document. The namespace document 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
    • getDestinationNamespace

      @BsonIgnore @Nullable public MongoNamespace getDestinationNamespace()
      Returns the destination namespace, derived from the "to" field in a change stream document.

      The destination namespace is used to indicate the destination of a collection rename event.

      Returns:
      the namespace. If the "to" document is null or absent, then this will return null.
      Since:
      3.11
      See Also:
    • getDestinationNamespaceDocument

      @BsonProperty("to") @Nullable public BsonDocument getDestinationNamespaceDocument()
      Returns the destination namespace document, derived from the "to" field in a change stream document.

      The destination namespace document 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 destinationNamespaceDocument
      Since:
      3.11
    • 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

      @Nullable public 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, or null if the event is not associated with a single document (e.g. a collection rename event)
    • getClusterTime

      @Nullable public 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
    • getOperationTypeString

      public String getOperationTypeString()
      Returns the operation type as a string.

      This method is useful when using a driver release that has not yet been updated to include a newer operation type in the OperationType enum. In that case, getOperationType() will return OperationType.OTHER and this method can be used to retrieve the actual operation type as a string value.

      Returns:
      the operation type as a string
      Since:
      4.6
      See Also:
    • getOperationType

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

      @Nullable public UpdateDescription getUpdateDescription()
      Returns the updateDescription
      Returns:
      the updateDescription, or null if the event is not associated with a single document (e.g. a collection rename event)
    • getTxnNumber

      @Nullable public BsonInt64 getTxnNumber()
      Returns the transaction number
      Returns:
      the transaction number, or null if not part of a multi-document transaction
      Since:
      3.11
      Since server release
      4.0
    • getLsid

      @Nullable public BsonDocument getLsid()
      Returns the identifier for the session associated with the transaction
      Returns:
      the lsid, or null if not part of a multi-document transaction
      Since:
      3.11
      Since server release
      4.0
    • createCodec

      public static <TFullDocument> Codec<ChangeStreamDocument<TFullDocument>> createCodec(Class<TFullDocument> fullDocumentClass, 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
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object