Stay organized with collections Save and categorize content based on your preferences.
A DocumentChange represents a change to the documents matching a query. It contains the document affected and the type of change that occurred.
DocumentChange
Package@google-cloud/firestore Constructors (constructor)(type, document, oldIndex, newIndex)constructor(type: DocumentChangeType, document: QueryDocumentSnapshot<AppModelType, DbModelType>, oldIndex: number, newIndex: number);
Constructs a new instance of the DocumentChange
class
type
DocumentChangeType
'added' | 'removed' | 'modified'.
document
QueryDocumentSnapshot<AppModelType, DbModelType>
The document.
oldIndex
number
The index in the documents array prior to this change.
newIndex
number
The index in the documents array after this change.
Properties docget doc(): QueryDocumentSnapshot<AppModelType, DbModelType>;
The document affected by this change.
{QueryDocumentSnapshot} DocumentChange#doc
Example
let query = firestore.collection('col').where('foo', '==', 'bar');
let unsubscribe = query.onSnapshot(querySnapshot => {
for (let change of querySnapshot.docChanges) {
console.log(change.doc.data());
}
});
// Remove this listener.
unsubscribe();
newIndex
The index of the changed document in the result set immediately after this DocumentChange (i.e. supposing that all prior DocumentChange objects and the current DocumentChange object have been applied). Is -1 for 'removed' events.
{number} DocumentChange#newIndex
Example
let query = firestore.collection('col').where('foo', '==', 'bar');
let docsArray = [];
let unsubscribe = query.onSnapshot(querySnapshot => {
for (let change of querySnapshot.docChanges) {
if (change.oldIndex !== -1) {
docsArray.splice(change.oldIndex, 1);
}
if (change.newIndex !== -1) {
docsArray.splice(change.newIndex, 0, change.doc);
}
}
});
// Remove this listener.
unsubscribe();
oldIndex
The index of the changed document in the result set immediately prior to this DocumentChange (i.e. supposing that all prior DocumentChange objects have been applied). Is -1 for 'added' events.
{number} DocumentChange#oldIndex
Example
let query = firestore.collection('col').where('foo', '==', 'bar');
let docsArray = [];
let unsubscribe = query.onSnapshot(querySnapshot => {
for (let change of querySnapshot.docChanges) {
if (change.oldIndex !== -1) {
docsArray.splice(change.oldIndex, 1);
}
if (change.newIndex !== -1) {
docsArray.splice(change.newIndex, 0, change.doc);
}
}
});
// Remove this listener.
unsubscribe();
type
get type(): DocumentChangeType;
The type of change ('added', 'modified', or 'removed').
{string} DocumentChange#type
Example
let query = firestore.collection('col').where('foo', '==', 'bar');
let docsArray = [];
let unsubscribe = query.onSnapshot(querySnapshot => {
for (let change of querySnapshot.docChanges) {
console.log(`Type of change is ${change.type}`);
}
});
// Remove this listener.
unsubscribe();
Methods isEqual(other)
isEqual(other: firestore.DocumentChange<AppModelType, DbModelType>): boolean;
Returns true if the data in this DocumentChange
is equal to the provided value.
other
FirebaseFirestore.DocumentChange<AppModelType, DbModelType>
The value to compare against. true if this DocumentChange
is equal to the provided value.
boolean
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4