letquery=firestore.collection('col').where('foo','==','bar');letunsubscribe=query.onSnapshot(querySnapshot=>{for(letchangeofquerySnapshot.docChanges){console.log(change.doc.data());}});// Remove this listener.unsubscribe();
newIndex
getnewIndex():number;
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
letquery=firestore.collection('col').where('foo','==','bar');letdocsArray=[];letunsubscribe=query.onSnapshot(querySnapshot=>{for(letchangeofquerySnapshot.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
getoldIndex():number;
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
letquery=firestore.collection('col').where('foo','==','bar');letdocsArray=[];letunsubscribe=query.onSnapshot(querySnapshot=>{for(letchangeofquerySnapshot.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
gettype():DocumentChangeType;
The type of change ('added', 'modified', or 'removed').
{string} DocumentChange#type
Example
letquery=firestore.collection('col').where('foo','==','bar');letdocsArray=[];letunsubscribe=query.onSnapshot(querySnapshot=>{for(letchangeofquerySnapshot.docChanges){console.log(`Type of change is ${change.type}`);}});// Remove this listener.unsubscribe();
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class DocumentChange (7.11.0)\n\nVersion latestkeyboard_arrow_down\n\n- [7.11.0 (latest)](/nodejs/docs/reference/firestore/latest/firestore/documentchange)\n- [7.9.0](/nodejs/docs/reference/firestore/7.9.0/firestore/documentchange)\n- [7.7.0](/nodejs/docs/reference/firestore/7.7.0/firestore/documentchange)\n- [7.6.0](/nodejs/docs/reference/firestore/7.6.0/firestore/documentchange)\n- [7.5.0](/nodejs/docs/reference/firestore/7.5.0/firestore/documentchange)\n- [7.4.0](/nodejs/docs/reference/firestore/7.4.0/firestore/documentchange)\n- [7.3.1](/nodejs/docs/reference/firestore/7.3.1/firestore/documentchange)\n- [7.2.0](/nodejs/docs/reference/firestore/7.2.0/firestore/documentchange)\n- [7.1.0](/nodejs/docs/reference/firestore/7.1.0/firestore/documentchange)\n- [6.4.1](/nodejs/docs/reference/firestore/6.4.1/firestore/documentchange)\n- [6.3.0](/nodejs/docs/reference/firestore/6.3.0/firestore/documentchange)\n- [6.0.0](/nodejs/docs/reference/firestore/6.0.0/firestore/documentchange)\n- [5.0.2](/nodejs/docs/reference/firestore/5.0.2/firestore/documentchange)\n- [4.15.1](/nodejs/docs/reference/firestore/4.15.1/firestore/documentchange)\n- [4.14.2](/nodejs/docs/reference/firestore/4.14.2/firestore/documentchange)\n- [4.9.8](/nodejs/docs/reference/firestore/4.9.8/firestore/documentchange) \nA DocumentChange represents a change to the documents matching a query. It contains the document affected and the type of change that occurred.\n\nDocumentChange\n\nPackage\n-------\n\n[@google-cloud/firestore](../overview.html)\n\nConstructors\n------------\n\n### (constructor)(type, document, oldIndex, newIndex)\n\n constructor(type: DocumentChangeType, document: QueryDocumentSnapshot\u003cAppModelType, DbModelType\u003e, oldIndex: number, newIndex: number);\n\nConstructs a new instance of the `DocumentChange` class\n\nProperties\n----------\n\n### doc\n\n get doc(): QueryDocumentSnapshot\u003cAppModelType, DbModelType\u003e;\n\nThe document affected by this change.\n\n{QueryDocumentSnapshot} DocumentChange#doc\n**Example** \n\n\n let query = firestore.collection('col').where('foo', '==', 'bar');\n\n let unsubscribe = query.onSnapshot(querySnapshot =\u003e {\n for (let change of querySnapshot.docChanges) {\n console.log(change.doc.data());\n }\n });\n\n // Remove this listener.\n unsubscribe();\n\n### newIndex\n\n get newIndex(): number;\n\nThe 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.\n\n{number} DocumentChange#newIndex\n**Example** \n\n\n let query = firestore.collection('col').where('foo', '==', 'bar');\n let docsArray = [];\n\n let unsubscribe = query.onSnapshot(querySnapshot =\u003e {\n for (let change of querySnapshot.docChanges) {\n if (change.oldIndex !== -1) {\n docsArray.splice(change.oldIndex, 1);\n }\n if (change.newIndex !== -1) {\n docsArray.splice(change.newIndex, 0, change.doc);\n }\n }\n });\n\n // Remove this listener.\n unsubscribe();\n\n### oldIndex\n\n get oldIndex(): number;\n\nThe 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.\n\n{number} DocumentChange#oldIndex\n**Example** \n\n\n let query = firestore.collection('col').where('foo', '==', 'bar');\n let docsArray = [];\n\n let unsubscribe = query.onSnapshot(querySnapshot =\u003e {\n for (let change of querySnapshot.docChanges) {\n if (change.oldIndex !== -1) {\n docsArray.splice(change.oldIndex, 1);\n }\n if (change.newIndex !== -1) {\n docsArray.splice(change.newIndex, 0, change.doc);\n }\n }\n });\n\n // Remove this listener.\n unsubscribe();\n\n### type\n\n get type(): DocumentChangeType;\n\nThe type of change ('added', 'modified', or 'removed').\n\n{string} DocumentChange#type\n**Example** \n\n\n let query = firestore.collection('col').where('foo', '==', 'bar');\n let docsArray = [];\n\n let unsubscribe = query.onSnapshot(querySnapshot =\u003e {\n for (let change of querySnapshot.docChanges) {\n console.log(`Type of change is ${change.type}`);\n }\n });\n\n // Remove this listener.\n unsubscribe();\n\nMethods\n-------\n\n### isEqual(other)\n\n isEqual(other: firestore.DocumentChange\u003cAppModelType, DbModelType\u003e): boolean;\n\nReturns true if the data in this `DocumentChange` is equal to the provided value."]]