DocumentChange

public classDocumentChange


ADocumentChange represents a change to the documents matching a query. It contains the document affected and a the type of change that occurred (added, modified, or removed).

Subclassing Note: Cloud Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Summary

Nested types

An enumeration of snapshot diff types.

Public fields

finalQueryDocumentSnapshot
final int

The index in the new snapshot, after processing all previous changes.

final int

The index in the old snapshot, after processing all previous changes.

finalDocumentChange.Type

Public methods

boolean
@NonNullQueryDocumentSnapshot

Returns the newly added or modified document if thisDocumentChange is for an updated document.

int

The index of the changed document in the result set immediately after thisDocumentChange (assuming that all priorDocumentChange objects and the currentDocumentChange object have been applied).

int

The index of the changed document in the result set immediately prior to thisDocumentChange (assuming that all priorDocumentChange objects have been applied).

@NonNullDocumentChange.Type
int

Public fields

document

public final QueryDocumentSnapshot document

newIndex

public final int newIndex

The index in the new snapshot, after processing all previous changes.

oldIndex

public final int oldIndex

The index in the old snapshot, after processing all previous changes.

type

public final DocumentChange.Type type

Public methods

equals

public boolean equals(@NullableObject object)

getDocument

public @NonNullQueryDocumentSnapshot getDocument()

Returns the newly added or modified document if thisDocumentChange is for an updated document. Returns the deleted document if this document change represents a removal.

Returns
@NonNullQueryDocumentSnapshot

A snapshot of the new data (forADDED orMODIFIED) or the removed data (forREMOVED).

getNewIndex

public int getNewIndex()

The index of the changed document in the result set immediately after thisDocumentChange (assuming that all priorDocumentChange objects and the currentDocumentChange object have been applied). Returns -1 for 'removed' events.

getOldIndex

public int getOldIndex()

The index of the changed document in the result set immediately prior to thisDocumentChange (assuming that all priorDocumentChange objects have been applied). Returns -1 for 'added' events.

hashCode

public int hashCode()

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.